@forklaunch/implementation-worker-bullmq 0.1.4 → 0.1.6

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.
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=schemaEquality.test.d.ts.map
2
+ //# sourceMappingURL=schemaEquality.test.d.ts.map
@@ -3,14 +3,22 @@ import { testSchemaEquality } from '@forklaunch/core/test';
3
3
  import { BullMqWorkerOptionsSchema as TypeboxBullMqWorkerOptionsSchema } from '../schemas/typebox/bullMqWorker.schema';
4
4
  import { BullMqWorkerOptionsSchema as ZodBullMqWorkerOptionsSchema } from '../schemas/zod/bullMqWorker.schema';
5
5
  describe('schema equality', () => {
6
- it('should be equal for bullmq worker', () => {
7
- expect(isTrue(testSchemaEquality(ZodBullMqWorkerOptionsSchema, TypeboxBullMqWorkerOptionsSchema, {
6
+ it('should be equal for bullmq worker', () => {
7
+ expect(
8
+ isTrue(
9
+ testSchemaEquality(
10
+ ZodBullMqWorkerOptionsSchema,
11
+ TypeboxBullMqWorkerOptionsSchema,
12
+ {
8
13
  backoffType: 'fixed',
9
14
  retries: 1,
10
15
  interval: 1000,
11
16
  connection: {
12
- url: 'redis://localhost:6379'
17
+ url: 'redis://localhost:6379'
13
18
  }
14
- }))).toBeTruthy();
15
- });
19
+ }
20
+ )
21
+ )
22
+ ).toBeTruthy();
23
+ });
16
24
  });
@@ -1,16 +1,29 @@
1
1
  import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
- import { WorkerEventEntity, WorkerFailureHandler, WorkerProcessFunction } from '@forklaunch/interfaces-worker/types';
3
- import { WorkerOptions } from '../types/bullMqWorker.types';
4
- export declare class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends WorkerOptions> implements WorkerConsumer<EventEntity> {
5
- protected readonly queueName: string;
6
- protected readonly options: Options;
7
- protected readonly processEvents: WorkerProcessFunction<EventEntity>;
8
- protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
9
- private queue;
10
- private worker?;
11
- constructor(queueName: string, options: Options, processEvents: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
12
- peekEvents(): Promise<EventEntity[]>;
13
- start(): Promise<void>;
14
- close(): Promise<void>;
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerFailureHandler,
5
+ WorkerProcessFunction
6
+ } from '@forklaunch/interfaces-worker/types';
7
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
8
+ export declare class BullMqWorkerConsumer<
9
+ EventEntity extends WorkerEventEntity,
10
+ Options extends BullMqWorkerOptions
11
+ > implements WorkerConsumer<EventEntity>
12
+ {
13
+ protected readonly queueName: string;
14
+ protected readonly options: Options;
15
+ protected readonly processEvents: WorkerProcessFunction<EventEntity>;
16
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
17
+ private queue;
18
+ private worker?;
19
+ constructor(
20
+ queueName: string,
21
+ options: Options,
22
+ processEvents: WorkerProcessFunction<EventEntity>,
23
+ failureHandler: WorkerFailureHandler<EventEntity>
24
+ );
25
+ peekEvents(): Promise<EventEntity[]>;
26
+ start(): Promise<void>;
27
+ close(): Promise<void>;
15
28
  }
16
- //# sourceMappingURL=bullMqWorker.consumer.d.ts.map
29
+ //# sourceMappingURL=bullMqWorker.consumer.d.ts.map
@@ -1 +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,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,qBAAa,oBAAoB,CAC/B,WAAW,SAAS,iBAAiB,EACrC,OAAO,SAAS,aAAa,CAC7B,YAAW,cAAc,CAAC,WAAW,CAAC;I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AO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,MAAM,CAAC,CAAS;gBAGH,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,EAChB,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"}
@@ -1,42 +1,46 @@
1
1
  import { Queue, Worker } from 'bullmq';
2
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
- }
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(
24
+ this.queueName,
25
+ async (job) => {
26
+ const event = job.data;
27
+ await this.processEvents([event]);
28
+ },
29
+ this.options
30
+ );
31
+ this.worker.on('failed', (job, error) => {
32
+ if (job) {
33
+ this.failureHandler([
34
+ {
35
+ value: job.data,
36
+ error
37
+ }
38
+ ]);
39
+ }
40
+ });
41
+ }
42
+ async close() {
43
+ await this.worker?.close();
44
+ await this.queue.close();
45
+ }
42
46
  }
@@ -1,2 +1,2 @@
1
1
  export * from './bullMqWorker.consumer';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
@@ -5,11 +5,11 @@ import {
5
5
  WorkerProcessFunction
6
6
  } from '@forklaunch/interfaces-worker/types';
7
7
  import { Job, Queue, Worker } from 'bullmq';
8
- import { WorkerOptions } from '../types/bullMqWorker.types';
8
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
9
9
 
10
10
  export class BullMqWorkerConsumer<
11
11
  EventEntity extends WorkerEventEntity,
12
- Options extends WorkerOptions
12
+ Options extends BullMqWorkerOptions
13
13
  > implements WorkerConsumer<EventEntity>
14
14
  {
15
15
  private queue: Queue;
@@ -1,11 +1,11 @@
1
1
  import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
2
  import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
3
  import { Queue } from 'bullmq';
4
- import { WorkerOptions } from '../types/bullMqWorker.types';
4
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
5
5
 
6
6
  export class BullMqWorkerProducer<
7
7
  EventEntity extends WorkerEventEntity,
8
- Options extends WorkerOptions
8
+ Options extends BullMqWorkerOptions
9
9
  > implements WorkerProducer<EventEntity>
10
10
  {
11
11
  private queue;
@@ -1,6 +1,6 @@
1
1
  import { QueueOptions } from 'bullmq';
2
2
 
3
- export type WorkerOptions = QueueOptions & {
3
+ export type BullMqWorkerOptions = QueueOptions & {
4
4
  backoffType: 'exponential' | 'fixed';
5
5
  retries: number;
6
6
  interval: number;
@@ -1,4 +1,4 @@
1
1
  import type { JestConfigWithTsJest } from 'ts-jest';
2
2
  declare const jestConfig: JestConfigWithTsJest;
3
3
  export default jestConfig;
4
- //# sourceMappingURL=jest.config.d.ts.map
4
+ //# sourceMappingURL=jest.config.d.ts.map
@@ -1,19 +1,19 @@
1
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/']
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
18
  };
19
19
  export default jestConfig;
@@ -1,12 +1,16 @@
1
1
  import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
2
  import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
- import { WorkerOptions } from '../types/bullMqWorker.types';
4
- export declare class BullMqWorkerProducer<EventEntity extends WorkerEventEntity, Options extends WorkerOptions> implements WorkerProducer<EventEntity> {
5
- private readonly queueName;
6
- private readonly options;
7
- private queue;
8
- constructor(queueName: string, options: Options);
9
- enqueueJob(event: EventEntity): Promise<void>;
10
- enqueueBatchJobs(events: EventEntity[]): Promise<void>;
3
+ import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
4
+ export declare class BullMqWorkerProducer<
5
+ EventEntity extends WorkerEventEntity,
6
+ Options extends BullMqWorkerOptions
7
+ > implements WorkerProducer<EventEntity>
8
+ {
9
+ private readonly queueName;
10
+ private readonly options;
11
+ private queue;
12
+ constructor(queueName: string, options: Options);
13
+ enqueueJob(event: EventEntity): Promise<void>;
14
+ enqueueBatchJobs(events: EventEntity[]): Promise<void>;
11
15
  }
12
- //# sourceMappingURL=bullMqWorker.producer.d.ts.map
16
+ //# sourceMappingURL=bullMqWorker.producer.d.ts.map
@@ -1 +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,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,qBAAa,oBAAoB,CAC/B,WAAW,SAAS,iBAAiB,EACrC,OAAO,SAAS,aAAa,CAC7B,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,OAAO;IAO7B,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAe7D"}
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,CAC/B,WAAW,SAAS,iBAAiB,EACrC,OAAO,SAAS,mBAAmB,CACnC,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,OAAO;IAO7B,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAe7D"}
@@ -1,35 +1,37 @@
1
1
  import { Queue } from 'bullmq';
2
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
- }
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(
24
+ events.map((event) => ({
25
+ name: event.id,
26
+ data: event,
27
+ opts: {
28
+ attempts: this.options.retries,
29
+ backoff: {
30
+ type: this.options.backoffType,
31
+ delay: this.options.interval
32
+ }
33
+ }
34
+ }))
35
+ );
36
+ }
35
37
  }
@@ -1,2 +1,2 @@
1
1
  export * from './bullMqWorker.producer';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map