@forklaunch/implementation-worker-bullmq 0.1.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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/lib/__test__/schemaEquality.test.d.ts +2 -0
  3. package/lib/__test__/schemaEquality.test.d.ts.map +1 -0
  4. package/lib/__test__/schemaEquality.test.js +16 -0
  5. package/lib/consumers/bullMqWorker.consumer.d.ts +16 -0
  6. package/lib/consumers/bullMqWorker.consumer.d.ts.map +1 -0
  7. package/lib/consumers/bullMqWorker.consumer.js +42 -0
  8. package/lib/consumers/index.d.ts +2 -0
  9. package/lib/consumers/index.d.ts.map +1 -0
  10. package/lib/consumers/index.js +1 -0
  11. package/lib/eject/consumers/bullMqWorker.consumer.ts +58 -0
  12. package/lib/eject/consumers/index.ts +1 -0
  13. package/lib/eject/domain/schemas/bullMqWorker.schema.ts +153 -0
  14. package/lib/eject/domain/schemas/index.ts +1 -0
  15. package/lib/eject/producers/bullMqWorker.producer.ts +44 -0
  16. package/lib/eject/producers/index.ts +1 -0
  17. package/lib/eject/types/bullMqWorker.types.ts +7 -0
  18. package/lib/eject/types/index.ts +1 -0
  19. package/lib/jest.config.d.ts +4 -0
  20. package/lib/jest.config.d.ts.map +1 -0
  21. package/lib/jest.config.js +19 -0
  22. package/lib/producers/bullMqWorker.producer.d.ts +12 -0
  23. package/lib/producers/bullMqWorker.producer.d.ts.map +1 -0
  24. package/lib/producers/bullMqWorker.producer.js +35 -0
  25. package/lib/producers/index.d.ts +2 -0
  26. package/lib/producers/index.d.ts.map +1 -0
  27. package/lib/producers/index.js +1 -0
  28. package/lib/schemas/bullMqWorker.schema.d.ts +386 -0
  29. package/lib/schemas/bullMqWorker.schema.d.ts.map +1 -0
  30. package/lib/schemas/bullMqWorker.schema.js +4 -0
  31. package/lib/schemas/index.d.ts +2 -0
  32. package/lib/schemas/index.d.ts.map +1 -0
  33. package/lib/schemas/index.js +1 -0
  34. package/lib/schemas/typebox/bullMqWorker.schema.d.ts +82 -0
  35. package/lib/schemas/typebox/bullMqWorker.schema.d.ts.map +1 -0
  36. package/lib/schemas/typebox/bullMqWorker.schema.js +104 -0
  37. package/lib/schemas/zod/bullMqWorker.schema.d.ts +306 -0
  38. package/lib/schemas/zod/bullMqWorker.schema.d.ts.map +1 -0
  39. package/lib/schemas/zod/bullMqWorker.schema.js +104 -0
  40. package/lib/tsconfig.tsbuildinfo +1 -0
  41. package/lib/types/bullMqWorker.types.d.ts +7 -0
  42. package/lib/types/bullMqWorker.types.d.ts.map +1 -0
  43. package/lib/types/bullMqWorker.types.js +1 -0
  44. package/lib/types/index.d.ts +2 -0
  45. package/lib/types/index.d.ts.map +1 -0
  46. package/lib/types/index.js +1 -0
  47. package/lib/vitest.config.d.ts +3 -0
  48. package/lib/vitest.config.d.ts.map +1 -0
  49. package/lib/vitest.config.js +7 -0
  50. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 forklaunch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schemaEquality.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEquality.test.d.ts","sourceRoot":"","sources":["../../__test__/schemaEquality.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import { isTrue } from '@forklaunch/common';
2
+ import { testSchemaEquality } from '@forklaunch/core/test';
3
+ import { BullMqWorkerOptionsSchema as TypeboxBullMqWorkerOptionsSchema } from '../schemas/typebox/bullMqWorker.schema';
4
+ import { BullMqWorkerOptionsSchema as ZodBullMqWorkerOptionsSchema } from '../schemas/zod/bullMqWorker.schema';
5
+ describe('schema equality', () => {
6
+ it('should be equal for bullmq worker', () => {
7
+ expect(isTrue(testSchemaEquality(ZodBullMqWorkerOptionsSchema, TypeboxBullMqWorkerOptionsSchema, {
8
+ backoffType: 'fixed',
9
+ retries: 1,
10
+ interval: 1000,
11
+ connection: {
12
+ url: 'redis://localhost:6379'
13
+ }
14
+ }))).toBeTruthy();
15
+ });
16
+ });
@@ -0,0 +1,16 @@
1
+ import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
+ import { WorkerEventEntity, WorkerFailureHandler, WorkerProcessFunction } from '@forklaunch/interfaces-worker/types';
3
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
4
+ export declare class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity> implements WorkerConsumer<EventEntity> {
5
+ protected readonly queueName: string;
6
+ protected readonly options: BullMqWorkerOptions;
7
+ protected readonly processEvents: WorkerProcessFunction<EventEntity>;
8
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
9
+ private queue;
10
+ private worker?;
11
+ constructor(queueName: string, options: BullMqWorkerOptions, processEvents: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
12
+ peekEvents(): Promise<EventEntity[]>;
13
+ start(): Promise<void>;
14
+ close(): Promise<void>;
15
+ }
16
+ //# sourceMappingURL=bullMqWorker.consumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bullMqWorker.consumer.d.ts","sourceRoot":"","sources":["../../consumers/bullMqWorker.consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,qBAAa,oBAAoB,CAAC,WAAW,SAAS,iBAAiB,CACrE,YAAW,cAAc,CAAC,WAAW,CAAC;IAMpC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM;IACpC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,mBAAmB;IAC/C,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC,WAAW,CAAC;IACpE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,oBAAoB,CAAC,WAAW,CAAC;IAPtE,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,MAAM,CAAC,CAAS;gBAGH,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,mBAAmB,EAC5B,aAAa,EAAE,qBAAqB,CAAC,WAAW,CAAC,EACjD,cAAc,EAAE,oBAAoB,CAAC,WAAW,CAAC;IAOhE,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAKpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
@@ -0,0 +1,42 @@
1
+ import { Queue, Worker } from 'bullmq';
2
+ export class BullMqWorkerConsumer {
3
+ queueName;
4
+ options;
5
+ processEvents;
6
+ failureHandler;
7
+ queue;
8
+ worker;
9
+ constructor(queueName, options, processEvents, failureHandler) {
10
+ this.queueName = queueName;
11
+ this.options = options;
12
+ this.processEvents = processEvents;
13
+ this.failureHandler = failureHandler;
14
+ this.queue = new Queue(this.queueName, {
15
+ connection: this.options.connection
16
+ });
17
+ }
18
+ async peekEvents() {
19
+ const jobs = await this.queue.getJobs(['waiting', 'active']);
20
+ return jobs.map((job) => job.data);
21
+ }
22
+ async start() {
23
+ this.worker = new Worker(this.queueName, async (job) => {
24
+ const event = job.data;
25
+ await this.processEvents([event]);
26
+ }, this.options);
27
+ this.worker.on('failed', (job, error) => {
28
+ if (job) {
29
+ this.failureHandler([
30
+ {
31
+ value: job.data,
32
+ error
33
+ }
34
+ ]);
35
+ }
36
+ });
37
+ }
38
+ async close() {
39
+ await this.worker?.close();
40
+ await this.queue.close();
41
+ }
42
+ }
@@ -0,0 +1,2 @@
1
+ export * from './bullMqWorker.consumer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../consumers/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './bullMqWorker.consumer';
@@ -0,0 +1,58 @@
1
+ import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerFailureHandler,
5
+ WorkerProcessFunction
6
+ } from '@forklaunch/interfaces-worker/types';
7
+ import { Job, Queue, Worker } from 'bullmq';
8
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
9
+
10
+ export class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity>
11
+ implements WorkerConsumer<EventEntity>
12
+ {
13
+ private queue: Queue;
14
+ private worker?: Worker;
15
+
16
+ constructor(
17
+ protected readonly queueName: string,
18
+ protected readonly options: BullMqWorkerOptions,
19
+ protected readonly processEvents: WorkerProcessFunction<EventEntity>,
20
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>
21
+ ) {
22
+ this.queue = new Queue(this.queueName, {
23
+ connection: this.options.connection
24
+ });
25
+ }
26
+
27
+ async peekEvents(): Promise<EventEntity[]> {
28
+ const jobs = await this.queue.getJobs(['waiting', 'active']);
29
+ return jobs.map((job) => job.data as EventEntity);
30
+ }
31
+
32
+ async start(): Promise<void> {
33
+ this.worker = new Worker(
34
+ this.queueName,
35
+ async (job: Job) => {
36
+ const event = job.data as EventEntity;
37
+ await this.processEvents([event]);
38
+ },
39
+ this.options
40
+ );
41
+
42
+ this.worker.on('failed', (job: Job | undefined, error: Error) => {
43
+ if (job) {
44
+ this.failureHandler([
45
+ {
46
+ value: job.data as EventEntity,
47
+ error
48
+ }
49
+ ]);
50
+ }
51
+ });
52
+ }
53
+
54
+ async close(): Promise<void> {
55
+ await this.worker?.close();
56
+ await this.queue.close();
57
+ }
58
+ }
@@ -0,0 +1 @@
1
+ export * from './bullMqWorker.consumer';
@@ -0,0 +1,153 @@
1
+ import {
2
+ any,
3
+ array,
4
+ boolean,
5
+ date,
6
+ enum_,
7
+ function_,
8
+ literal,
9
+ null_,
10
+ number,
11
+ optional,
12
+ promise,
13
+ record,
14
+ string,
15
+ undefined_,
16
+ union,
17
+ unknown,
18
+ void_
19
+ } from '@{{app_name}}/core';
20
+ import { SpanKind } from 'bullmq';
21
+
22
+ const BullMqWorkerKeepJobsSchema = {
23
+ age: optional(number),
24
+ count: optional(number)
25
+ };
26
+
27
+ const BullMqWorkerBackoffOptionsSchema = {
28
+ type: union([literal('fixed'), literal('exponential')]),
29
+ delay: optional(number)
30
+ };
31
+
32
+ const BullMqWorkerDefaultJobOptionsSchema = {
33
+ timestamp: optional(number),
34
+ priority: optional(number),
35
+ delay: optional(number),
36
+ attempts: optional(number),
37
+ backoff: optional(union([number, BullMqWorkerBackoffOptionsSchema])),
38
+ lifo: optional(boolean),
39
+ removeOnComplete: optional(
40
+ union([boolean, number, BullMqWorkerKeepJobsSchema])
41
+ ),
42
+ removeOnFail: optional(union([boolean, number, BullMqWorkerKeepJobsSchema])),
43
+ keepLogs: optional(number),
44
+ stackTraceLimit: optional(number),
45
+ sizeLimit: optional(number)
46
+ };
47
+
48
+ const BullMqWorkerAdvancedRepeatOptionsSchema = {
49
+ repeatStrategy: optional(
50
+ function_(
51
+ [
52
+ number,
53
+ {
54
+ pattern: optional(string),
55
+ key: optional(string),
56
+ limit: optional(number),
57
+ every: optional(number),
58
+ immediately: optional(boolean),
59
+ count: optional(number),
60
+ offset: optional(number),
61
+ prevMillis: optional(number),
62
+ jobId: optional(string),
63
+ currentDate: optional(date),
64
+ startDate: optional(date),
65
+ endDate: optional(date),
66
+ utc: optional(boolean),
67
+ tz: optional(string),
68
+ nthDayOfWeek: optional(number)
69
+ },
70
+ optional(string)
71
+ ],
72
+ union([number, undefined_, promise(union([number, undefined_]))])
73
+ )
74
+ ),
75
+ repeatKeyHashAlgorithm: optional(string)
76
+ };
77
+
78
+ const BullMqWorkerTelemetryAttributeValueSchema = union([
79
+ string,
80
+ number,
81
+ boolean,
82
+ array(union([string, null_, undefined_])),
83
+ array(union([number, null_, undefined_])),
84
+ array(union([boolean, null_, undefined_]))
85
+ ]);
86
+
87
+ const BullMqWorkerTelemetryAttributesSchema = record(
88
+ string,
89
+ union([BullMqWorkerTelemetryAttributeValueSchema, undefined_])
90
+ );
91
+
92
+ const BullMqWorkerTelemetrySchema = optional({
93
+ tracer: {
94
+ startSpan: function_(
95
+ [
96
+ string,
97
+ optional({
98
+ kind: optional(enum_(SpanKind))
99
+ }),
100
+ optional(unknown)
101
+ ],
102
+ {
103
+ setSpanOnContext: function_([unknown], unknown),
104
+ setAttribute: function_(
105
+ [string, BullMqWorkerTelemetryAttributeValueSchema],
106
+ void_
107
+ ),
108
+ setAttributes: function_(
109
+ [BullMqWorkerTelemetryAttributesSchema],
110
+ void_
111
+ ),
112
+ addEvent: function_(
113
+ [string, optional(BullMqWorkerTelemetryAttributesSchema)],
114
+ void_
115
+ ),
116
+ recordException: function_([unknown, optional(number)], void_),
117
+ end: function_([], void_)
118
+ }
119
+ )
120
+ },
121
+ contextManager: {
122
+ with: function_([unknown, function_([any], any)], any),
123
+ active: function_([], unknown),
124
+ getMetadata: function_([unknown], string),
125
+ fromMetadata: function_([unknown, string], unknown)
126
+ }
127
+ });
128
+
129
+ const BullMqWorkerQueueOptionsSchema = {
130
+ connection: {
131
+ skipVersionCheck: optional(boolean),
132
+ url: optional(string)
133
+ },
134
+ blockingConnection: optional(boolean),
135
+ prefix: optional(string),
136
+ telemetry: BullMqWorkerTelemetrySchema,
137
+ skipWaitingForReady: optional(boolean),
138
+ defaultJobOptions: optional(BullMqWorkerDefaultJobOptionsSchema),
139
+ streams: optional({
140
+ events: {
141
+ maxLen: number
142
+ }
143
+ }),
144
+ skipMetasUpdate: optional(boolean),
145
+ settings: optional(BullMqWorkerAdvancedRepeatOptionsSchema)
146
+ };
147
+
148
+ export const BullMqWorkerOptionsSchema = {
149
+ ...BullMqWorkerQueueOptionsSchema,
150
+ backoffType: union([literal('exponential'), literal('fixed')]),
151
+ retries: number,
152
+ interval: number
153
+ };
@@ -0,0 +1 @@
1
+ export * from './bullMqWorker.schema';
@@ -0,0 +1,44 @@
1
+ import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
+ import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
+ import { Queue } from 'bullmq';
4
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
5
+
6
+ export class BullMqWorkerProducer<EventEntity extends WorkerEventEntity>
7
+ implements WorkerProducer<EventEntity>
8
+ {
9
+ private queue;
10
+
11
+ constructor(
12
+ private readonly queueName: string,
13
+ private readonly options: BullMqWorkerOptions
14
+ ) {
15
+ this.queue = new Queue(this.queueName, {
16
+ connection: this.options.connection
17
+ });
18
+ }
19
+
20
+ async enqueueJob(event: EventEntity): Promise<void> {
21
+ await this.queue.add(event.id, event, {
22
+ attempts: this.options.retries,
23
+ backoff: {
24
+ type: this.options.backoffType,
25
+ delay: this.options.interval
26
+ }
27
+ });
28
+ }
29
+ async enqueueBatchJobs(events: EventEntity[]): Promise<void> {
30
+ await this.queue.addBulk(
31
+ events.map((event) => ({
32
+ name: event.id,
33
+ data: event,
34
+ opts: {
35
+ attempts: this.options.retries,
36
+ backoff: {
37
+ type: this.options.backoffType,
38
+ delay: this.options.interval
39
+ }
40
+ }
41
+ }))
42
+ );
43
+ }
44
+ }
@@ -0,0 +1 @@
1
+ export * from './bullMqWorker.producer';
@@ -0,0 +1,7 @@
1
+ import { QueueOptions } from 'bullmq';
2
+
3
+ export type BullMqWorkerOptions = QueueOptions & {
4
+ backoffType: 'exponential' | 'fixed';
5
+ retries: number;
6
+ interval: number;
7
+ };
@@ -0,0 +1 @@
1
+ export * from './bullMqWorker.types';
@@ -0,0 +1,4 @@
1
+ import type { JestConfigWithTsJest } from 'ts-jest';
2
+ declare const jestConfig: JestConfigWithTsJest;
3
+ export default jestConfig;
4
+ //# sourceMappingURL=jest.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.config.d.ts","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,QAAA,MAAM,UAAU,EAAE,oBAiBjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,19 @@
1
+ const jestConfig = {
2
+ preset: 'ts-jest/presets/default-esm', // or other ESM presets
3
+ moduleNameMapper: {
4
+ '^(\\.{1,2}/.*)\\.js$': '$1'
5
+ },
6
+ transform: {
7
+ // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`
8
+ // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`
9
+ '^.+\\.[tj]sx?$': [
10
+ 'ts-jest',
11
+ {
12
+ useESM: true
13
+ }
14
+ ],
15
+ '^.+\\.js$': 'babel-jest'
16
+ },
17
+ testPathIgnorePatterns: ['.*dist/', '.*node_modules/']
18
+ };
19
+ export default jestConfig;
@@ -0,0 +1,12 @@
1
+ import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
+ import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
4
+ export declare class BullMqWorkerProducer<EventEntity extends WorkerEventEntity> implements WorkerProducer<EventEntity> {
5
+ private readonly queueName;
6
+ private readonly options;
7
+ private queue;
8
+ constructor(queueName: string, options: BullMqWorkerOptions);
9
+ enqueueJob(event: EventEntity): Promise<void>;
10
+ enqueueBatchJobs(events: EventEntity[]): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=bullMqWorker.producer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bullMqWorker.producer.d.ts","sourceRoot":"","sources":["../../producers/bullMqWorker.producer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,qBAAa,oBAAoB,CAAC,WAAW,SAAS,iBAAiB,CACrE,YAAW,cAAc,CAAC,WAAW,CAAC;IAKpC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,KAAK,CAAC;gBAGK,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,mBAAmB;IAOzC,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAe7D"}
@@ -0,0 +1,35 @@
1
+ import { Queue } from 'bullmq';
2
+ export class BullMqWorkerProducer {
3
+ queueName;
4
+ options;
5
+ queue;
6
+ constructor(queueName, options) {
7
+ this.queueName = queueName;
8
+ this.options = options;
9
+ this.queue = new Queue(this.queueName, {
10
+ connection: this.options.connection
11
+ });
12
+ }
13
+ async enqueueJob(event) {
14
+ await this.queue.add(event.id, event, {
15
+ attempts: this.options.retries,
16
+ backoff: {
17
+ type: this.options.backoffType,
18
+ delay: this.options.interval
19
+ }
20
+ });
21
+ }
22
+ async enqueueBatchJobs(events) {
23
+ await this.queue.addBulk(events.map((event) => ({
24
+ name: event.id,
25
+ data: event,
26
+ opts: {
27
+ attempts: this.options.retries,
28
+ backoff: {
29
+ type: this.options.backoffType,
30
+ delay: this.options.interval
31
+ }
32
+ }
33
+ })));
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './bullMqWorker.producer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../producers/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './bullMqWorker.producer';