@forklaunch/implementation-worker-bullmq 0.3.1 → 0.3.3

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.
@@ -0,0 +1,10 @@
1
+ import { QueueOptions } from 'bullmq';
2
+
3
+ type BullMqWorkerOptions = {
4
+ queueOptions: QueueOptions;
5
+ backoffType: 'exponential' | 'fixed';
6
+ retries: number;
7
+ interval: number;
8
+ };
9
+
10
+ export type { BullMqWorkerOptions };
@@ -0,0 +1,10 @@
1
+ import { QueueOptions } from 'bullmq';
2
+
3
+ type BullMqWorkerOptions = {
4
+ queueOptions: QueueOptions;
5
+ backoffType: 'exponential' | 'fixed';
6
+ retries: number;
7
+ interval: number;
8
+ };
9
+
10
+ export type { BullMqWorkerOptions };
@@ -1,18 +1,22 @@
1
- "use strict";
1
+ 'use strict';
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
7
+ if ((from && typeof from === 'object') || typeof from === 'function') {
8
8
  for (let key of __getOwnPropNames(from))
9
9
  if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ __defProp(to, key, {
11
+ get: () => from[key],
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
11
14
  }
12
15
  return to;
13
16
  };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
17
+ var __toCommonJS = (mod) =>
18
+ __copyProps(__defProp({}, '__esModule', { value: true }), mod);
15
19
 
16
- // types/index.ts
20
+ // domain/types/index.ts
17
21
  var types_exports = {};
18
22
  module.exports = __toCommonJS(types_exports);
@@ -5,7 +5,7 @@ import {
5
5
  WorkerProcessFunction
6
6
  } from '@forklaunch/interfaces-worker/types';
7
7
  import { Job, Queue, Worker } from 'bullmq';
8
- import { BullMqWorkerOptions } from '../types/bullMqWorker.types';
8
+ import { BullMqWorkerOptions } from '../domain/types/bullMqWorker.types';
9
9
 
10
10
  export class BullMqWorkerConsumer<
11
11
  EventEntity extends WorkerEventEntity,
@@ -22,7 +22,7 @@ export class BullMqWorkerConsumer<
22
22
  protected readonly failureHandler: WorkerFailureHandler<EventEntity>
23
23
  ) {
24
24
  this.queue = new Queue(this.queueName, {
25
- connection: this.options.connection
25
+ connection: this.options.queueOptions.connection
26
26
  });
27
27
  }
28
28
 
@@ -38,7 +38,7 @@ export class BullMqWorkerConsumer<
38
38
  const event = job.data as EventEntity;
39
39
  await this.processEvents([event]);
40
40
  },
41
- this.options
41
+ this.options.queueOptions
42
42
  );
43
43
 
44
44
  this.worker.on('failed', (job: Job | undefined, error: Error) => {
@@ -1,154 +1,8 @@
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 BullMqDateType = union([date, number, string]);
49
-
50
- const BullMqWorkerAdvancedRepeatOptionsSchema = {
51
- repeatStrategy: optional(
52
- function_(
53
- [
54
- number,
55
- {
56
- pattern: optional(string),
57
- key: optional(string),
58
- limit: optional(number),
59
- every: optional(number),
60
- immediately: optional(boolean),
61
- count: optional(number),
62
- offset: optional(number),
63
- prevMillis: optional(number),
64
- jobId: optional(string),
65
- currentDate: optional(BullMqDateType),
66
- startDate: optional(BullMqDateType),
67
- endDate: optional(BullMqDateType),
68
- utc: optional(boolean),
69
- tz: optional(string),
70
- nthDayOfWeek: optional(number)
71
- },
72
- optional(string)
73
- ],
74
- union([number, undefined_, promise(union([number, undefined_]))])
75
- )
76
- ),
77
- repeatKeyHashAlgorithm: optional(string)
78
- };
79
-
80
- const BullMqWorkerTelemetryAttributeValueSchema = union([
81
- string,
82
- number,
83
- boolean,
84
- array(union([string, null_, undefined_])),
85
- array(union([number, null_, undefined_])),
86
- array(union([boolean, null_, undefined_]))
87
- ]);
88
-
89
- const BullMqWorkerTelemetryAttributesSchema = record(
90
- string,
91
- union([BullMqWorkerTelemetryAttributeValueSchema, undefined_])
92
- );
93
-
94
- const BullMqWorkerTelemetrySchema = optional({
95
- tracer: {
96
- startSpan: function_(
97
- [
98
- string,
99
- optional({
100
- kind: optional(enum_(SpanKind))
101
- }),
102
- optional(unknown)
103
- ],
104
- {
105
- setSpanOnContext: function_([unknown], unknown),
106
- setAttribute: function_(
107
- [string, BullMqWorkerTelemetryAttributeValueSchema],
108
- void_
109
- ),
110
- setAttributes: function_(
111
- [BullMqWorkerTelemetryAttributesSchema],
112
- void_
113
- ),
114
- addEvent: function_(
115
- [string, optional(BullMqWorkerTelemetryAttributesSchema)],
116
- void_
117
- ),
118
- recordException: function_([unknown, optional(number)], void_),
119
- end: function_([], void_)
120
- }
121
- )
122
- },
123
- contextManager: {
124
- with: function_([unknown, function_([any], any)], any),
125
- active: function_([], unknown),
126
- getMetadata: function_([unknown], string),
127
- fromMetadata: function_([unknown, string], unknown)
128
- }
129
- });
130
-
131
- const BullMqWorkerQueueOptionsSchema = {
132
- connection: {
133
- skipVersionCheck: optional(boolean),
134
- url: optional(string)
135
- },
136
- blockingConnection: optional(boolean),
137
- prefix: optional(string),
138
- telemetry: BullMqWorkerTelemetrySchema,
139
- skipWaitingForReady: optional(boolean),
140
- defaultJobOptions: optional(BullMqWorkerDefaultJobOptionsSchema),
141
- streams: optional({
142
- events: {
143
- maxLen: number
144
- }
145
- }),
146
- skipMetasUpdate: optional(boolean),
147
- settings: optional(BullMqWorkerAdvancedRepeatOptionsSchema)
148
- };
1
+ import { literal, number, type, union } from '@{{app_name}}/core';
2
+ import { QueueOptions } from 'bullmq';
149
3
 
150
4
  export const BullMqWorkerOptionsSchema = {
151
- ...BullMqWorkerQueueOptionsSchema,
5
+ queueOptions: type<QueueOptions>(),
152
6
  backoffType: union([literal('exponential'), literal('fixed')]),
153
7
  retries: number,
154
8
  interval: number
@@ -1,6 +1,7 @@
1
1
  import { QueueOptions } from 'bullmq';
2
2
 
3
- export type BullMqWorkerOptions = QueueOptions & {
3
+ export type BullMqWorkerOptions = {
4
+ queueOptions: QueueOptions;
4
5
  backoffType: 'exponential' | 'fixed';
5
6
  retries: number;
6
7
  interval: number;
@@ -1,7 +1,7 @@
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 { BullMqWorkerOptions } from '../types/bullMqWorker.types';
4
+ import { BullMqWorkerOptions } from '../domain/types/bullMqWorker.types';
5
5
 
6
6
  export class BullMqWorkerProducer<
7
7
  EventEntity extends WorkerEventEntity,
@@ -15,7 +15,7 @@ export class BullMqWorkerProducer<
15
15
  private readonly options: Options
16
16
  ) {
17
17
  this.queue = new Queue(this.queueName, {
18
- connection: this.options.connection
18
+ connection: this.options.queueOptions.connection
19
19
  });
20
20
  }
21
21
 
@@ -1,15 +1,19 @@
1
1
  import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
2
  import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
- import { BullMqWorkerOptions } from '../types/index.mjs';
3
+ import { BullMqWorkerOptions } from '../domain/types/index.mjs';
4
4
  import 'bullmq';
5
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>;
6
+ declare class BullMqWorkerProducer<
7
+ EventEntity extends WorkerEventEntity,
8
+ Options extends BullMqWorkerOptions
9
+ > implements WorkerProducer<EventEntity>
10
+ {
11
+ private readonly queueName;
12
+ private readonly options;
13
+ private queue;
14
+ constructor(queueName: string, options: Options);
15
+ enqueueJob(event: EventEntity): Promise<void>;
16
+ enqueueBatchJobs(events: EventEntity[]): Promise<void>;
13
17
  }
14
18
 
15
19
  export { BullMqWorkerProducer };
@@ -1,15 +1,19 @@
1
1
  import { WorkerProducer } from '@forklaunch/interfaces-worker/interfaces';
2
2
  import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
3
- import { BullMqWorkerOptions } from '../types/index.js';
3
+ import { BullMqWorkerOptions } from '../domain/types/index.js';
4
4
  import 'bullmq';
5
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>;
6
+ declare class BullMqWorkerProducer<
7
+ EventEntity extends WorkerEventEntity,
8
+ Options extends BullMqWorkerOptions
9
+ > implements WorkerProducer<EventEntity>
10
+ {
11
+ private readonly queueName;
12
+ private readonly options;
13
+ private queue;
14
+ constructor(queueName: string, options: Options);
15
+ enqueueJob(event: EventEntity): Promise<void>;
16
+ enqueueBatchJobs(events: EventEntity[]): Promise<void>;
13
17
  }
14
18
 
15
19
  export { BullMqWorkerProducer };
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -8,14 +8,18 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
11
+ if ((from && typeof from === 'object') || typeof from === 'function') {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
15
18
  }
16
19
  return to;
17
20
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __toCommonJS = (mod) =>
22
+ __copyProps(__defProp({}, '__esModule', { value: true }), mod);
19
23
 
20
24
  // producers/index.ts
21
25
  var producers_exports = {};
@@ -25,13 +29,13 @@ __export(producers_exports, {
25
29
  module.exports = __toCommonJS(producers_exports);
26
30
 
27
31
  // producers/bullMqWorker.producer.ts
28
- var import_bullmq = require("bullmq");
32
+ var import_bullmq = require('bullmq');
29
33
  var BullMqWorkerProducer = class {
30
34
  constructor(queueName, options) {
31
35
  this.queueName = queueName;
32
36
  this.options = options;
33
37
  this.queue = new import_bullmq.Queue(this.queueName, {
34
- connection: this.options.connection
38
+ connection: this.options.queueOptions.connection
35
39
  });
36
40
  }
37
41
  queue;
@@ -61,6 +65,7 @@ var BullMqWorkerProducer = class {
61
65
  }
62
66
  };
63
67
  // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- BullMqWorkerProducer
66
- });
68
+ 0 &&
69
+ (module.exports = {
70
+ BullMqWorkerProducer
71
+ });
@@ -1,11 +1,11 @@
1
1
  // producers/bullMqWorker.producer.ts
2
- import { Queue } from "bullmq";
2
+ import { Queue } from 'bullmq';
3
3
  var BullMqWorkerProducer = class {
4
4
  constructor(queueName, options) {
5
5
  this.queueName = queueName;
6
6
  this.options = options;
7
7
  this.queue = new Queue(this.queueName, {
8
- connection: this.options.connection
8
+ connection: this.options.queueOptions.connection
9
9
  });
10
10
  }
11
11
  queue;
@@ -34,6 +34,4 @@ var BullMqWorkerProducer = class {
34
34
  );
35
35
  }
36
36
  };
37
- export {
38
- BullMqWorkerProducer
39
- };
37
+ export { BullMqWorkerProducer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-worker-bullmq",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "BullMQ implementation for forklaunch workers",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -26,38 +26,39 @@
26
26
  "default": "./lib/producers/index.js"
27
27
  },
28
28
  "./schemas": {
29
- "types": "./lib/schemas/index.d.ts",
30
- "import": "./lib/schemas/index.mjs",
31
- "require": "./lib/schemas/index.js",
32
- "default": "./lib/schemas/index.js"
29
+ "types": "./lib/domain/schemas/index.d.ts",
30
+ "import": "./lib/domain/schemas/index.mjs",
31
+ "require": "./lib/domain/schemas/index.js",
32
+ "default": "./lib/domain/schemas/index.js"
33
33
  },
34
34
  "./types": {
35
- "types": "./lib/types/index.d.ts",
36
- "import": "./lib/types/index.mjs",
37
- "require": "./lib/types/index.js",
38
- "default": "./lib/types/index.js"
35
+ "types": "./lib/domain/types/index.d.ts",
36
+ "import": "./lib/domain/types/index.mjs",
37
+ "require": "./lib/domain/types/index.js",
38
+ "default": "./lib/domain/types/index.js"
39
39
  }
40
40
  },
41
41
  "files": [
42
42
  "lib/**"
43
43
  ],
44
44
  "dependencies": {
45
- "@forklaunch/core": "^0.9.15",
46
- "@sinclair/typebox": "^0.34.33",
47
- "bullmq": "^5.53.2",
48
- "zod": "^3.25.63",
49
- "@forklaunch/interfaces-worker": "0.2.1"
45
+ "@forklaunch/core": "^0.9.21",
46
+ "@forklaunch/internal": "^0.0.7",
47
+ "@sinclair/typebox": "^0.34.35",
48
+ "bullmq": "^5.54.3",
49
+ "zod": "^3.25.67",
50
+ "@forklaunch/interfaces-worker": "0.2.2"
50
51
  },
51
52
  "devDependencies": {
52
- "@typescript/native-preview": "7.0.0-dev.20250611.1",
53
+ "@typescript/native-preview": "7.0.0-dev.20250619.1",
53
54
  "depcheck": "^1.4.7",
54
- "eslint": "^9.28.0",
55
+ "eslint": "^9.29.0",
55
56
  "prettier": "^3.5.3",
56
57
  "typedoc": "^0.28.5",
57
- "typescript-eslint": "^8.34.0"
58
+ "typescript-eslint": "^8.34.1"
58
59
  },
59
60
  "scripts": {
60
- "build": "tsc --noEmit && tsup producers/index.ts consumers/index.ts schemas/index.ts types/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean && if [ -f eject-package.bash ]; then pnpm package:eject; fi",
61
+ "build": "tsc --noEmit && tsup producers/index.ts consumers/index.ts domain/schemas/index.ts domain/types/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean && if [ -f eject-package.bash ]; then pnpm package:eject; fi",
61
62
  "clean": "rm -rf lib pnpm.lock.yaml node_modules",
62
63
  "docs": "typedoc --out docs *",
63
64
  "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",