@forklaunch/implementation-worker-bullmq 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/consumers/index.d.mts +19 -0
- package/lib/consumers/index.d.ts +19 -2
- package/lib/consumers/index.js +73 -1
- package/lib/consumers/{bullMqWorker.consumer.js → index.mjs} +11 -11
- package/lib/producers/index.d.mts +15 -0
- package/lib/producers/index.d.ts +15 -2
- package/lib/producers/index.js +66 -1
- package/lib/producers/{bullMqWorker.producer.js → index.mjs} +8 -6
- package/lib/schemas/index.d.mts +390 -0
- package/lib/schemas/index.d.ts +390 -2
- package/lib/schemas/index.js +1613 -1
- package/lib/schemas/index.mjs +1617 -0
- package/lib/types/index.d.mts +9 -0
- package/lib/types/index.d.ts +9 -2
- package/lib/types/index.js +18 -1
- package/lib/types/index.mjs +0 -0
- package/package.json +5 -4
- package/lib/__test__/schemaEquality.test.d.ts +0 -2
- package/lib/__test__/schemaEquality.test.d.ts.map +0 -1
- package/lib/__test__/schemaEquality.test.js +0 -24
- package/lib/consumers/bullMqWorker.consumer.d.ts +0 -29
- package/lib/consumers/bullMqWorker.consumer.d.ts.map +0 -1
- package/lib/consumers/index.d.ts.map +0 -1
- package/lib/jest.config.d.ts +0 -4
- package/lib/jest.config.d.ts.map +0 -1
- package/lib/jest.config.js +0 -19
- package/lib/producers/bullMqWorker.producer.d.ts +0 -16
- package/lib/producers/bullMqWorker.producer.d.ts.map +0 -1
- package/lib/producers/index.d.ts.map +0 -1
- package/lib/schemas/bullMqWorker.schema.d.ts +0 -2117
- package/lib/schemas/bullMqWorker.schema.d.ts.map +0 -1
- package/lib/schemas/bullMqWorker.schema.js +0 -7
- package/lib/schemas/index.d.ts.map +0 -1
- package/lib/schemas/typebox/bullMqWorker.schema.d.ts +0 -1016
- package/lib/schemas/typebox/bullMqWorker.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/bullMqWorker.schema.js +0 -145
- package/lib/schemas/zod/bullMqWorker.schema.d.ts +0 -1066
- package/lib/schemas/zod/bullMqWorker.schema.d.ts.map +0 -1
- package/lib/schemas/zod/bullMqWorker.schema.js +0 -145
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types/bullMqWorker.types.d.ts +0 -7
- package/lib/types/bullMqWorker.types.d.ts.map +0 -1
- package/lib/types/bullMqWorker.types.js +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
|
|
2
|
+
import { WorkerEventEntity, WorkerProcessFunction, WorkerFailureHandler } from '@forklaunch/interfaces-worker/types';
|
|
3
|
+
import { BullMqWorkerOptions } from '../types/index.mjs';
|
|
4
|
+
import 'bullmq';
|
|
5
|
+
|
|
6
|
+
declare class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends BullMqWorkerOptions> implements WorkerConsumer<EventEntity> {
|
|
7
|
+
protected readonly queueName: string;
|
|
8
|
+
protected readonly options: Options;
|
|
9
|
+
protected readonly processEvents: WorkerProcessFunction<EventEntity>;
|
|
10
|
+
protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
|
|
11
|
+
private queue;
|
|
12
|
+
private worker?;
|
|
13
|
+
constructor(queueName: string, options: Options, processEvents: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
|
|
14
|
+
peekEvents(): Promise<EventEntity[]>;
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { BullMqWorkerConsumer };
|
package/lib/consumers/index.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
|
|
2
|
+
import { WorkerEventEntity, WorkerProcessFunction, WorkerFailureHandler } from '@forklaunch/interfaces-worker/types';
|
|
3
|
+
import { BullMqWorkerOptions } from '../types/index.js';
|
|
4
|
+
import 'bullmq';
|
|
5
|
+
|
|
6
|
+
declare class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends BullMqWorkerOptions> implements WorkerConsumer<EventEntity> {
|
|
7
|
+
protected readonly queueName: string;
|
|
8
|
+
protected readonly options: Options;
|
|
9
|
+
protected readonly processEvents: WorkerProcessFunction<EventEntity>;
|
|
10
|
+
protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
|
|
11
|
+
private queue;
|
|
12
|
+
private worker?;
|
|
13
|
+
constructor(queueName: string, options: Options, processEvents: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
|
|
14
|
+
peekEvents(): Promise<EventEntity[]>;
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { BullMqWorkerConsumer };
|
package/lib/consumers/index.js
CHANGED
|
@@ -1 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// consumers/index.ts
|
|
21
|
+
var consumers_exports = {};
|
|
22
|
+
__export(consumers_exports, {
|
|
23
|
+
BullMqWorkerConsumer: () => BullMqWorkerConsumer
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(consumers_exports);
|
|
26
|
+
|
|
27
|
+
// consumers/bullMqWorker.consumer.ts
|
|
28
|
+
var import_bullmq = require("bullmq");
|
|
29
|
+
var BullMqWorkerConsumer = class {
|
|
30
|
+
constructor(queueName, options, processEvents, failureHandler) {
|
|
31
|
+
this.queueName = queueName;
|
|
32
|
+
this.options = options;
|
|
33
|
+
this.processEvents = processEvents;
|
|
34
|
+
this.failureHandler = failureHandler;
|
|
35
|
+
this.queue = new import_bullmq.Queue(this.queueName, {
|
|
36
|
+
connection: this.options.connection
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
queue;
|
|
40
|
+
worker;
|
|
41
|
+
async peekEvents() {
|
|
42
|
+
const jobs = await this.queue.getJobs(["waiting", "active"]);
|
|
43
|
+
return jobs.map((job) => job.data);
|
|
44
|
+
}
|
|
45
|
+
async start() {
|
|
46
|
+
this.worker = new import_bullmq.Worker(
|
|
47
|
+
this.queueName,
|
|
48
|
+
async (job) => {
|
|
49
|
+
const event = job.data;
|
|
50
|
+
await this.processEvents([event]);
|
|
51
|
+
},
|
|
52
|
+
this.options
|
|
53
|
+
);
|
|
54
|
+
this.worker.on("failed", (job, error) => {
|
|
55
|
+
if (job) {
|
|
56
|
+
this.failureHandler([
|
|
57
|
+
{
|
|
58
|
+
value: job.data,
|
|
59
|
+
error
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async close() {
|
|
66
|
+
await this.worker?.close();
|
|
67
|
+
await this.queue.close();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
BullMqWorkerConsumer
|
|
73
|
+
});
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
options;
|
|
5
|
-
processEvents;
|
|
6
|
-
failureHandler;
|
|
7
|
-
queue;
|
|
8
|
-
worker;
|
|
1
|
+
// consumers/bullMqWorker.consumer.ts
|
|
2
|
+
import { Queue, Worker } from "bullmq";
|
|
3
|
+
var BullMqWorkerConsumer = class {
|
|
9
4
|
constructor(queueName, options, processEvents, failureHandler) {
|
|
10
5
|
this.queueName = queueName;
|
|
11
6
|
this.options = options;
|
|
@@ -15,8 +10,10 @@ export class BullMqWorkerConsumer {
|
|
|
15
10
|
connection: this.options.connection
|
|
16
11
|
});
|
|
17
12
|
}
|
|
13
|
+
queue;
|
|
14
|
+
worker;
|
|
18
15
|
async peekEvents() {
|
|
19
|
-
const jobs = await this.queue.getJobs([
|
|
16
|
+
const jobs = await this.queue.getJobs(["waiting", "active"]);
|
|
20
17
|
return jobs.map((job) => job.data);
|
|
21
18
|
}
|
|
22
19
|
async start() {
|
|
@@ -28,7 +25,7 @@ export class BullMqWorkerConsumer {
|
|
|
28
25
|
},
|
|
29
26
|
this.options
|
|
30
27
|
);
|
|
31
|
-
this.worker.on(
|
|
28
|
+
this.worker.on("failed", (job, error) => {
|
|
32
29
|
if (job) {
|
|
33
30
|
this.failureHandler([
|
|
34
31
|
{
|
|
@@ -43,4 +40,7 @@ export class BullMqWorkerConsumer {
|
|
|
43
40
|
await this.worker?.close();
|
|
44
41
|
await this.queue.close();
|
|
45
42
|
}
|
|
46
|
-
}
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
BullMqWorkerConsumer
|
|
46
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
|
|
2
|
+
import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
|
|
3
|
+
import { BullMqWorkerOptions } from '../types/index.mjs';
|
|
4
|
+
import 'bullmq';
|
|
5
|
+
|
|
6
|
+
declare class BullMqWorkerProducer<EventEntity extends WorkerEventEntity, Options extends BullMqWorkerOptions> implements WorkerProducer<EventEntity> {
|
|
7
|
+
private readonly queueName;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private queue;
|
|
10
|
+
constructor(queueName: string, options: Options);
|
|
11
|
+
enqueueJob(event: EventEntity): Promise<void>;
|
|
12
|
+
enqueueBatchJobs(events: EventEntity[]): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { BullMqWorkerProducer };
|
package/lib/producers/index.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
|
|
2
|
+
import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
|
|
3
|
+
import { BullMqWorkerOptions } from '../types/index.js';
|
|
4
|
+
import 'bullmq';
|
|
5
|
+
|
|
6
|
+
declare class BullMqWorkerProducer<EventEntity extends WorkerEventEntity, Options extends BullMqWorkerOptions> implements WorkerProducer<EventEntity> {
|
|
7
|
+
private readonly queueName;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private queue;
|
|
10
|
+
constructor(queueName: string, options: Options);
|
|
11
|
+
enqueueJob(event: EventEntity): Promise<void>;
|
|
12
|
+
enqueueBatchJobs(events: EventEntity[]): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { BullMqWorkerProducer };
|
package/lib/producers/index.js
CHANGED
|
@@ -1 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// producers/index.ts
|
|
21
|
+
var producers_exports = {};
|
|
22
|
+
__export(producers_exports, {
|
|
23
|
+
BullMqWorkerProducer: () => BullMqWorkerProducer
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(producers_exports);
|
|
26
|
+
|
|
27
|
+
// producers/bullMqWorker.producer.ts
|
|
28
|
+
var import_bullmq = require("bullmq");
|
|
29
|
+
var BullMqWorkerProducer = class {
|
|
30
|
+
constructor(queueName, options) {
|
|
31
|
+
this.queueName = queueName;
|
|
32
|
+
this.options = options;
|
|
33
|
+
this.queue = new import_bullmq.Queue(this.queueName, {
|
|
34
|
+
connection: this.options.connection
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
queue;
|
|
38
|
+
async enqueueJob(event) {
|
|
39
|
+
await this.queue.add(event.id, event, {
|
|
40
|
+
attempts: this.options.retries,
|
|
41
|
+
backoff: {
|
|
42
|
+
type: this.options.backoffType,
|
|
43
|
+
delay: this.options.interval
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async enqueueBatchJobs(events) {
|
|
48
|
+
await this.queue.addBulk(
|
|
49
|
+
events.map((event) => ({
|
|
50
|
+
name: event.id,
|
|
51
|
+
data: event,
|
|
52
|
+
opts: {
|
|
53
|
+
attempts: this.options.retries,
|
|
54
|
+
backoff: {
|
|
55
|
+
type: this.options.backoffType,
|
|
56
|
+
delay: this.options.interval
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
BullMqWorkerProducer
|
|
66
|
+
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
options;
|
|
5
|
-
queue;
|
|
1
|
+
// producers/bullMqWorker.producer.ts
|
|
2
|
+
import { Queue } from "bullmq";
|
|
3
|
+
var BullMqWorkerProducer = class {
|
|
6
4
|
constructor(queueName, options) {
|
|
7
5
|
this.queueName = queueName;
|
|
8
6
|
this.options = options;
|
|
@@ -10,6 +8,7 @@ export class BullMqWorkerProducer {
|
|
|
10
8
|
connection: this.options.connection
|
|
11
9
|
});
|
|
12
10
|
}
|
|
11
|
+
queue;
|
|
13
12
|
async enqueueJob(event) {
|
|
14
13
|
await this.queue.add(event.id, event, {
|
|
15
14
|
attempts: this.options.retries,
|
|
@@ -34,4 +33,7 @@ export class BullMqWorkerProducer {
|
|
|
34
33
|
}))
|
|
35
34
|
);
|
|
36
35
|
}
|
|
37
|
-
}
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
BullMqWorkerProducer
|
|
39
|
+
};
|