@forklaunch/implementation-worker-bullmq 0.1.0 → 0.1.1

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 (30) hide show
  1. package/lib/__test__/schemaEquality.test.d.ts +1 -1
  2. package/lib/__test__/schemaEquality.test.js +13 -5
  3. package/lib/consumers/bullMqWorker.consumer.d.ts +26 -13
  4. package/lib/consumers/bullMqWorker.consumer.d.ts.map +1 -1
  5. package/lib/consumers/bullMqWorker.consumer.js +43 -39
  6. package/lib/consumers/index.d.ts +1 -1
  7. package/lib/eject/consumers/bullMqWorker.consumer.ts +5 -3
  8. package/lib/eject/domain/schemas/bullMqWorker.schema.ts +5 -3
  9. package/lib/eject/producers/bullMqWorker.producer.ts +5 -3
  10. package/lib/jest.config.d.ts +1 -1
  11. package/lib/jest.config.js +16 -16
  12. package/lib/producers/bullMqWorker.producer.d.ts +12 -8
  13. package/lib/producers/bullMqWorker.producer.d.ts.map +1 -1
  14. package/lib/producers/bullMqWorker.producer.js +34 -32
  15. package/lib/producers/index.d.ts +1 -1
  16. package/lib/schemas/bullMqWorker.schema.d.ts +1949 -360
  17. package/lib/schemas/bullMqWorker.schema.js +4 -1
  18. package/lib/schemas/index.d.ts +1 -1
  19. package/lib/schemas/typebox/bullMqWorker.schema.d.ts +1019 -79
  20. package/lib/schemas/typebox/bullMqWorker.schema.d.ts.map +1 -1
  21. package/lib/schemas/typebox/bullMqWorker.schema.js +124 -83
  22. package/lib/schemas/zod/bullMqWorker.schema.d.ts +875 -261
  23. package/lib/schemas/zod/bullMqWorker.schema.d.ts.map +1 -1
  24. package/lib/schemas/zod/bullMqWorker.schema.js +124 -83
  25. package/lib/tsconfig.tsbuildinfo +1 -1
  26. package/lib/types/bullMqWorker.types.d.ts +4 -4
  27. package/lib/types/index.d.ts +1 -1
  28. package/lib/vitest.config.d.ts +2 -2
  29. package/lib/vitest.config.js +4 -4
  30. package/package.json +4 -4
@@ -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';
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerFailureHandler,
5
+ WorkerProcessFunction
6
+ } from '@forklaunch/interfaces-worker/types';
3
7
  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>;
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,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,QAA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AAW,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
@@ -7,15 +7,17 @@ import {
7
7
  import { Job, Queue, Worker } from 'bullmq';
8
8
  import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
9
9
 
10
- export class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity>
11
- implements WorkerConsumer<EventEntity>
10
+ export class BullMqWorkerConsumer<
11
+ EventEntity extends WorkerEventEntity,
12
+ Options extends BullMqWorkerOptions
13
+ > implements WorkerConsumer<EventEntity>
12
14
  {
13
15
  private queue: Queue;
14
16
  private worker?: Worker;
15
17
 
16
18
  constructor(
17
19
  protected readonly queueName: string,
18
- protected readonly options: BullMqWorkerOptions,
20
+ protected readonly options: Options,
19
21
  protected readonly processEvents: WorkerProcessFunction<EventEntity>,
20
22
  protected readonly failureHandler: WorkerFailureHandler<EventEntity>
21
23
  ) {
@@ -45,6 +45,8 @@ const BullMqWorkerDefaultJobOptionsSchema = {
45
45
  sizeLimit: optional(number)
46
46
  };
47
47
 
48
+ const BullMqDateType = union([date, number, string]);
49
+
48
50
  const BullMqWorkerAdvancedRepeatOptionsSchema = {
49
51
  repeatStrategy: optional(
50
52
  function_(
@@ -60,9 +62,9 @@ const BullMqWorkerAdvancedRepeatOptionsSchema = {
60
62
  offset: optional(number),
61
63
  prevMillis: optional(number),
62
64
  jobId: optional(string),
63
- currentDate: optional(date),
64
- startDate: optional(date),
65
- endDate: optional(date),
65
+ currentDate: optional(BullMqDateType),
66
+ startDate: optional(BullMqDateType),
67
+ endDate: optional(BullMqDateType),
66
68
  utc: optional(boolean),
67
69
  tz: optional(string),
68
70
  nthDayOfWeek: optional(number)
@@ -3,14 +3,16 @@ import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
3
  import { Queue } from 'bullmq';
4
4
  import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
5
5
 
6
- export class BullMqWorkerProducer<EventEntity extends WorkerEventEntity>
7
- implements WorkerProducer<EventEntity>
6
+ export class BullMqWorkerProducer<
7
+ EventEntity extends WorkerEventEntity,
8
+ Options extends BullMqWorkerOptions
9
+ > implements WorkerProducer<EventEntity>
8
10
  {
9
11
  private queue;
10
12
 
11
13
  constructor(
12
14
  private readonly queueName: string,
13
- private readonly options: BullMqWorkerOptions
15
+ private readonly options: Options
14
16
  ) {
15
17
  this.queue = new Queue(this.queueName, {
16
18
  connection: this.options.connection
@@ -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
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>;
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,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"}
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