@opens/bullmq 1.0.4 → 1.0.5

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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,50 @@
1
- import { BullMQWrapper } from './wrapper';
2
- export declare const bullmq: BullMQWrapper;
1
+ import * as BullMQ from 'bullmq';
2
+ import { Redis } from 'ioredis';
3
+
4
+ declare class BullMQWrapper {
5
+ private defaultConnection;
6
+ private taskQueues;
7
+ constructor(defaultConnection: Redis);
8
+ createTask(params: {
9
+ taskName: string;
10
+ defaultOptions: BullMQ.DefaultJobOptions;
11
+ connection?: Redis;
12
+ up?: (data: any, job: BullMQ.Job) => Promise<void>;
13
+ down?: (data: any, job: BullMQ.Job, err: unknown) => Promise<void>;
14
+ concurrency?: number;
15
+ removeOnCompleteAge?: number;
16
+ removeOnCompleteCount?: number;
17
+ removeOnFailAge?: number;
18
+ removeOnFailCount?: number;
19
+ }): {
20
+ queue: BullMQ.Queue<any, any, string, any, any, string>;
21
+ worker?: undefined;
22
+ } | {
23
+ queue: BullMQ.Queue<any, any, string, any, any, string>;
24
+ worker: BullMQ.Worker<any, any, string>;
25
+ } | undefined;
26
+ createWorker(params: {
27
+ taskName: string;
28
+ up: (data: any, job: BullMQ.Job) => Promise<void>;
29
+ down?: (data: any, job: BullMQ.Job, err: unknown) => Promise<void>;
30
+ connection?: Redis;
31
+ concurrency: number;
32
+ removeOnCompleteAge?: number;
33
+ removeOnCompleteCount?: number;
34
+ removeOnFailAge?: number;
35
+ removeOnFailCount?: number;
36
+ onError?: Function;
37
+ }): {
38
+ worker: BullMQ.Worker<any, any, string>;
39
+ };
40
+ publishTask(params: {
41
+ taskName: string;
42
+ taskData: any;
43
+ taskOptions: BullMQ.JobsOptions;
44
+ }): Promise<BullMQ.JobJson | null>;
45
+ getTaskCount(): number;
46
+ }
47
+
48
+ declare const bullmq: BullMQWrapper;
49
+
50
+ export { bullmq };
package/dist/index.js CHANGED
@@ -1,3 +1,131 @@
1
- import { BullMQWrapper } from './wrapper';
2
- import { DefaultConnection } from './default-connection';
3
- export const bullmq = new BullMQWrapper(DefaultConnection.getInstance());
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ bullmq: () => bullmq
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/wrapper.ts
38
+ var BullMQ = __toESM(require("bullmq"));
39
+ var BullMQWrapper = class {
40
+ constructor(defaultConnection) {
41
+ this.defaultConnection = defaultConnection;
42
+ }
43
+ taskQueues = /* @__PURE__ */ new Map();
44
+ createTask(params) {
45
+ const { taskName, up, down, defaultOptions, connection, concurrency } = params;
46
+ if (this.taskQueues.has(taskName)) return;
47
+ const queue = new BullMQ.Queue(taskName, {
48
+ connection: this.defaultConnection ?? connection,
49
+ defaultJobOptions: { backoff: { delay: 1e3 * 60 * 5, type: "fixed" }, attempts: 10, ...defaultOptions }
50
+ });
51
+ this.taskQueues.set(taskName, queue);
52
+ console.debug(`[@opens/bullmq]: task queue'${taskName}' created`);
53
+ if (!up) return { queue };
54
+ const { worker } = this.createWorker({
55
+ up,
56
+ down,
57
+ concurrency: concurrency ?? 1,
58
+ ...params
59
+ });
60
+ return { queue, worker };
61
+ }
62
+ createWorker(params) {
63
+ const {
64
+ taskName,
65
+ up,
66
+ down,
67
+ concurrency,
68
+ connection,
69
+ removeOnFailCount,
70
+ removeOnCompleteAge,
71
+ removeOnCompleteCount,
72
+ removeOnFailAge
73
+ } = params;
74
+ const registeredQueue = this.taskQueues.get(taskName);
75
+ if (!registeredQueue) throw new Error(`No task queue for [${taskName}] found`);
76
+ const worker = new BullMQ.Worker(
77
+ taskName,
78
+ async (job) => {
79
+ try {
80
+ await up(job.data, job);
81
+ } catch (error) {
82
+ if (down) await down(job.data, job, error);
83
+ throw error;
84
+ } finally {
85
+ }
86
+ },
87
+ {
88
+ concurrency,
89
+ connection: connection ?? this.defaultConnection,
90
+ removeOnComplete: {
91
+ age: removeOnCompleteAge ?? 0,
92
+ count: removeOnCompleteCount ?? 0
93
+ },
94
+ removeOnFail: {
95
+ age: removeOnFailAge ?? 0,
96
+ count: removeOnFailCount ?? 0
97
+ }
98
+ }
99
+ );
100
+ return { worker };
101
+ }
102
+ async publishTask(params) {
103
+ const queue = this.taskQueues.get(params.taskName);
104
+ if (!queue) return null;
105
+ const job = await queue.add("", params.taskData, params.taskOptions);
106
+ return job.asJSON();
107
+ }
108
+ getTaskCount() {
109
+ return this.taskQueues.size;
110
+ }
111
+ };
112
+
113
+ // src/default-connection.ts
114
+ var import_ioredis = require("ioredis");
115
+ var DefaultConnection = class {
116
+ static getInstance() {
117
+ const host = process.env.BULLMQ_REDIS_HOST;
118
+ const port = process.env.BULLMQ_REDIS_PORT;
119
+ if (!host) throw new Error("Environment variable ${BULLMQ_REDIS_HOST} is undefined");
120
+ if (!port) throw new Error("Environment variable ${BULLMQ_REDIS_PORT} is undefined");
121
+ return new import_ioredis.Redis({ host, port: parseInt(port), maxRetriesPerRequest: null });
122
+ }
123
+ };
124
+
125
+ // src/index.ts
126
+ var bullmq = new BullMQWrapper(DefaultConnection.getInstance());
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ bullmq
130
+ });
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/wrapper.ts","../src/default-connection.ts"],"sourcesContent":["import { BullMQWrapper } from './wrapper';\nimport { DefaultConnection } from './default-connection';\nexport const bullmq = new BullMQWrapper(DefaultConnection.getInstance());\n","import * as BullMQ from 'bullmq';\nimport { Redis } from 'ioredis';\n\nexport class BullMQWrapper {\n private taskQueues: Map<string, BullMQ.Queue> = new Map();\n\n constructor(private defaultConnection: Redis) {}\n\n public createTask(params: {\n taskName: string;\n defaultOptions: BullMQ.DefaultJobOptions;\n connection?: Redis;\n up?: (data: any, job: BullMQ.Job) => Promise<void>;\n down?: (data: any, job: BullMQ.Job, err: unknown) => Promise<void>;\n concurrency?: number;\n removeOnCompleteAge?: number;\n removeOnCompleteCount?: number;\n removeOnFailAge?: number;\n removeOnFailCount?: number;\n }) {\n const { taskName, up, down, defaultOptions, connection, concurrency } = params;\n if (this.taskQueues.has(taskName)) return;\n\n const queue = new BullMQ.Queue(taskName, {\n connection: this.defaultConnection ?? connection,\n defaultJobOptions: { backoff: { delay: 1000 * 60 * 5, type: 'fixed' }, attempts: 10, ...defaultOptions },\n });\n this.taskQueues.set(taskName, queue);\n console.debug(`[@opens/bullmq]: task queue'${taskName}' created`);\n if (!up) return { queue };\n\n const { worker } = this.createWorker({\n up,\n down,\n concurrency: concurrency ?? 1,\n ...params,\n });\n return { queue, worker };\n }\n\n public createWorker(params: {\n taskName: string;\n up: (data: any, job: BullMQ.Job) => Promise<void>;\n down?: (data: any, job: BullMQ.Job, err: unknown) => Promise<void>;\n connection?: Redis;\n concurrency: number;\n removeOnCompleteAge?: number;\n removeOnCompleteCount?: number;\n removeOnFailAge?: number;\n removeOnFailCount?: number;\n onError?: Function;\n }) {\n const {\n taskName,\n up,\n down,\n concurrency,\n connection,\n removeOnFailCount,\n removeOnCompleteAge,\n removeOnCompleteCount,\n removeOnFailAge,\n } = params;\n const registeredQueue = this.taskQueues.get(taskName);\n if (!registeredQueue) throw new Error(`No task queue for [${taskName}] found`);\n\n const worker = new BullMQ.Worker(\n taskName,\n async (job) => {\n try {\n await up(job.data, job);\n } catch (error) {\n if (down) await down(job.data, job, error);\n throw error;\n } finally {\n }\n },\n {\n concurrency,\n connection: connection ?? this.defaultConnection,\n removeOnComplete: {\n age: removeOnCompleteAge ?? 0,\n count: removeOnCompleteCount ?? 0,\n },\n removeOnFail: {\n age: removeOnFailAge ?? 0,\n count: removeOnFailCount ?? 0,\n },\n },\n );\n\n return { worker };\n }\n\n public async publishTask(params: { taskName: string; taskData: any; taskOptions: BullMQ.JobsOptions }) {\n const queue = this.taskQueues.get(params.taskName);\n if (!queue) return null;\n const job = await queue.add('', params.taskData, params.taskOptions);\n return job.asJSON();\n }\n\n public getTaskCount() {\n return this.taskQueues.size;\n }\n}\n","import { Redis } from 'ioredis';\nexport class DefaultConnection {\n static getInstance() {\n const host = process.env.BULLMQ_REDIS_HOST;\n const port = process.env.BULLMQ_REDIS_PORT;\n if (!host) throw new Error('Environment variable ${BULLMQ_REDIS_HOST} is undefined');\n if (!port) throw new Error('Environment variable ${BULLMQ_REDIS_PORT} is undefined');\n return new Redis({ host, port: parseInt(port), maxRetriesPerRequest: null });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC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AA,MACA;AAAA,QACE;AAAA,QACA,YAAY,cAAc,KAAK;AAAA,QAC/B,kBAAkB;AAAA,UAChB,KAAK,uBAAuB;AAAA,UAC5B,OAAO,yBAAyB;AAAA,QAClC;AAAA,QACA,cAAc;AAAA,UACZ,KAAK,mBAAmB;AAAA,UACxB,OAAO,qBAAqB;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,WAAO,EAAE,OAAO;AAAA,EAClB;AAAA,EAEA,MAAa,YAAY,QAA8E;AACrG,UAAM,QAAQ,KAAK,WAAW,IAAI,OAAO,QAAQ;AACjD,QAAI,CAAC,MAAO,QAAO;AACnB,UAAM,MAAM,MAAM,MAAM,IAAI,IAAI,OAAO,UAAU,OAAO,WAAW;AACnE,WAAO,IAAI,OAAO;AAAA,EACpB;AAAA,EAEO,eAAe;AACpB,WAAO,KAAK,WAAW;AAAA,EACzB;AACF;;;ACxGA,qBAAsB;AACf,IAAM,oBAAN,MAAwB;AAAA,EAC7B,OAAO,cAAc;AACnB,UAAM,OAAO,QAAQ,IAAI;AACzB,UAAM,OAAO,QAAQ,IAAI;AACzB,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,wDAAwD;AACnF,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,wDAAwD;AACnF,WAAO,IAAI,qBAAM,EAAE,MAAM,MAAM,SAAS,IAAI,GAAG,sBAAsB,KAAK,CAAC;AAAA,EAC7E;AACF;;;AFPO,IAAM,SAAS,IAAI,cAAc,kBAAkB,YAAY,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opens/bullmq",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A wrapper around bullmq",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "build": "tsc",
12
+ "build": "tsup --dts",
13
13
  "dev": "tsup --watch",
14
14
  "test": "vitest run",
15
15
  "test:watch": "vitest"
@@ -1,4 +0,0 @@
1
- import { Redis } from 'ioredis';
2
- export declare class DefaultConnection {
3
- static getInstance(): Redis;
4
- }
@@ -1,12 +0,0 @@
1
- import { Redis } from 'ioredis';
2
- export class DefaultConnection {
3
- static getInstance() {
4
- const host = process.env.BULLMQ_REDIS_HOST;
5
- const port = process.env.BULLMQ_REDIS_PORT;
6
- if (!host)
7
- throw new Error('Environment variable ${BULLMQ_REDIS_HOST} is undefined');
8
- if (!port)
9
- throw new Error('Environment variable ${BULLMQ_REDIS_PORT} is undefined');
10
- return new Redis({ host, port: parseInt(port), maxRetriesPerRequest: null });
11
- }
12
- }
package/dist/wrapper.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import BullMQ from 'bullmq';
2
- import { Redis } from 'ioredis';
3
- export declare class BullMQWrapper {
4
- private defaultConnection;
5
- private taskQueues;
6
- constructor(defaultConnection: Redis);
7
- createTask(params: {
8
- taskName: string;
9
- defaultOptions: BullMQ.DefaultJobOptions;
10
- connection?: Redis;
11
- up?: (data: any, job: BullMQ.Job) => Promise<void>;
12
- down?: (data: any, job: BullMQ.Job, err: unknown) => Promise<void>;
13
- concurrency?: number;
14
- removeOnCompleteAge?: number;
15
- removeOnCompleteCount?: number;
16
- removeOnFailAge?: number;
17
- removeOnFailCount?: number;
18
- }): {
19
- queue: BullMQ.Queue<any, any, string, any, any, string>;
20
- worker?: undefined;
21
- } | {
22
- queue: BullMQ.Queue<any, any, string, any, any, string>;
23
- worker: BullMQ.Worker<any, any, string>;
24
- } | undefined;
25
- createWorker(params: {
26
- taskName: string;
27
- up: (data: any, job: BullMQ.Job) => Promise<void>;
28
- down?: (data: any, job: BullMQ.Job, err: unknown) => Promise<void>;
29
- connection?: Redis;
30
- concurrency: number;
31
- removeOnCompleteAge?: number;
32
- removeOnCompleteCount?: number;
33
- removeOnFailAge?: number;
34
- removeOnFailCount?: number;
35
- onError?: Function;
36
- }): {
37
- worker: BullMQ.Worker<any, any, string>;
38
- };
39
- publishTask(params: {
40
- taskName: string;
41
- taskData: any;
42
- taskOptions: BullMQ.JobsOptions;
43
- }): Promise<BullMQ.JobJson | null>;
44
- getTaskCount(): number;
45
- }
package/dist/wrapper.js DELETED
@@ -1,68 +0,0 @@
1
- import BullMQ from 'bullmq';
2
- export class BullMQWrapper {
3
- defaultConnection;
4
- taskQueues = new Map();
5
- constructor(defaultConnection) {
6
- this.defaultConnection = defaultConnection;
7
- }
8
- createTask(params) {
9
- const { taskName, up, down, defaultOptions, connection, concurrency } = params;
10
- if (this.taskQueues.has(taskName))
11
- return;
12
- const queue = new BullMQ.Queue(taskName, {
13
- connection: this.defaultConnection ?? connection,
14
- defaultJobOptions: { backoff: { delay: 1000 * 60 * 5, type: 'fixed' }, attempts: 10, ...defaultOptions },
15
- });
16
- this.taskQueues.set(taskName, queue);
17
- console.debug("[@opens/bullmq]: task queue'${taskName}' created");
18
- if (!up)
19
- return { queue };
20
- const { worker } = this.createWorker({
21
- up,
22
- down,
23
- concurrency: concurrency ?? 1,
24
- ...params,
25
- });
26
- return { queue, worker };
27
- }
28
- createWorker(params) {
29
- const { taskName, up, down, concurrency, connection, removeOnFailCount, removeOnCompleteAge, removeOnCompleteCount, removeOnFailAge, } = params;
30
- const registeredQueue = this.taskQueues.get(taskName);
31
- if (!registeredQueue)
32
- throw new Error(`No task queue for [${taskName}] found`);
33
- const worker = new BullMQ.Worker(taskName, async (job) => {
34
- try {
35
- await up(job.data, job);
36
- }
37
- catch (error) {
38
- if (down)
39
- await down(job.data, job, error);
40
- throw error;
41
- }
42
- finally {
43
- }
44
- }, {
45
- concurrency,
46
- connection: connection ?? this.defaultConnection,
47
- removeOnComplete: {
48
- age: removeOnCompleteAge ?? 0,
49
- count: removeOnCompleteCount ?? 0,
50
- },
51
- removeOnFail: {
52
- age: removeOnFailAge ?? 0,
53
- count: removeOnFailCount ?? 0,
54
- },
55
- });
56
- return { worker };
57
- }
58
- async publishTask(params) {
59
- const queue = this.taskQueues.get(params.taskName);
60
- if (!queue)
61
- return null;
62
- const job = await queue.add('', params.taskData, params.taskOptions);
63
- return job.asJSON();
64
- }
65
- getTaskCount() {
66
- return this.taskQueues.size;
67
- }
68
- }