@forklaunch/implementation-worker-bullmq 0.1.2 → 0.1.4

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,22 +3,14 @@ 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(
8
- isTrue(
9
- testSchemaEquality(
10
- ZodBullMqWorkerOptionsSchema,
11
- TypeboxBullMqWorkerOptionsSchema,
12
- {
6
+ it('should be equal for bullmq worker', () => {
7
+ expect(isTrue(testSchemaEquality(ZodBullMqWorkerOptionsSchema, TypeboxBullMqWorkerOptionsSchema, {
13
8
  backoffType: 'fixed',
14
9
  retries: 1,
15
10
  interval: 1000,
16
11
  connection: {
17
- url: 'redis://localhost:6379'
12
+ url: 'redis://localhost:6379'
18
13
  }
19
- }
20
- )
21
- )
22
- ).toBeTruthy();
23
- });
14
+ }))).toBeTruthy();
15
+ });
24
16
  });
@@ -1,29 +1,16 @@
1
1
  import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
- import {
3
- WorkerEventEntity,
4
- WorkerFailureHandler,
5
- WorkerProcessFunction
6
- } from '@forklaunch/interfaces-worker/types';
2
+ import { WorkerEventEntity, WorkerFailureHandler, WorkerProcessFunction } from '@forklaunch/interfaces-worker/types';
7
3
  import { WorkerOptions } from '../types/bullMqWorker.types';
8
- export declare class BullMqWorkerConsumer<
9
- EventEntity extends WorkerEventEntity,
10
- Options extends WorkerOptions
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>;
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>;
28
15
  }
29
- //# sourceMappingURL=bullMqWorker.consumer.d.ts.map
16
+ //# sourceMappingURL=bullMqWorker.consumer.d.ts.map
@@ -1,46 +1,42 @@
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(
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
- }
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
+ }
46
42
  }
@@ -1,2 +1,2 @@
1
1
  export * from './bullMqWorker.consumer';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,16 +1,12 @@
1
1
  import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
2
  import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
3
  import { WorkerOptions } from '../types/bullMqWorker.types';
4
- export declare class BullMqWorkerProducer<
5
- EventEntity extends WorkerEventEntity,
6
- Options extends WorkerOptions
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>;
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>;
15
11
  }
16
- //# sourceMappingURL=bullMqWorker.producer.d.ts.map
12
+ //# sourceMappingURL=bullMqWorker.producer.d.ts.map
@@ -1,37 +1,35 @@
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(
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
- }
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
+ }
37
35
  }
@@ -1,2 +1,2 @@
1
1
  export * from './bullMqWorker.producer';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map