@motiadev/adapter-bullmq-events 0.14.0-beta.165-210612 → 0.14.0-beta.165-256670
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/LICENSE +1 -1
- package/dist/bullmq-event-adapter.d.ts +27 -0
- package/dist/bullmq-event-adapter.d.ts.map +1 -0
- package/dist/bullmq-event-adapter.js +75 -0
- package/dist/config-builder.d.ts +6 -0
- package/dist/config-builder.d.ts.map +1 -0
- package/dist/config-builder.js +29 -0
- package/dist/connection-manager.d.ts +10 -0
- package/dist/connection-manager.d.ts.map +1 -0
- package/dist/connection-manager.js +39 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/dlq-manager.d.ts +22 -0
- package/dist/dlq-manager.d.ts.map +1 -0
- package/dist/dlq-manager.js +112 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +35 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/queue-manager.d.ts +20 -0
- package/dist/queue-manager.d.ts.map +1 -0
- package/dist/queue-manager.js +85 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/worker-manager.d.ts +38 -0
- package/dist/worker-manager.d.ts.map +1 -0
- package/dist/worker-manager.js +136 -0
- package/package.json +7 -11
- package/tsconfig.json +2 -2
- package/dist/bullmq-event-adapter.d.mts +0 -31
- package/dist/bullmq-event-adapter.d.mts.map +0 -1
- package/dist/bullmq-event-adapter.mjs +0 -74
- package/dist/bullmq-event-adapter.mjs.map +0 -1
- package/dist/config-builder.d.mts +0 -9
- package/dist/config-builder.d.mts.map +0 -1
- package/dist/config-builder.mjs +0 -28
- package/dist/config-builder.mjs.map +0 -1
- package/dist/connection-manager.mjs +0 -35
- package/dist/connection-manager.mjs.map +0 -1
- package/dist/constants.mjs +0 -18
- package/dist/constants.mjs.map +0 -1
- package/dist/dlq-manager.d.mts +0 -26
- package/dist/dlq-manager.d.mts.map +0 -1
- package/dist/dlq-manager.mjs +0 -105
- package/dist/dlq-manager.mjs.map +0 -1
- package/dist/errors.mjs +0 -31
- package/dist/errors.mjs.map +0 -1
- package/dist/index.d.mts +0 -6
- package/dist/index.mjs +0 -6
- package/dist/queue-manager.d.mts +0 -24
- package/dist/queue-manager.d.mts.map +0 -1
- package/dist/queue-manager.mjs +0 -83
- package/dist/queue-manager.mjs.map +0 -1
- package/dist/types.d.mts +0 -27
- package/dist/types.d.mts.map +0 -1
- package/dist/worker-manager.d.mts +0 -41
- package/dist/worker-manager.d.mts.map +0 -1
- package/dist/worker-manager.mjs +0 -130
- package/dist/worker-manager.mjs.map +0 -1
- package/tsdown.config.ts +0 -17
package/LICENSE
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Event, EventAdapter, QueueConfig, SubscriptionHandle } from '@motiadev/core';
|
|
2
|
+
import type { Redis } from 'ioredis';
|
|
3
|
+
import { DLQManager } from './dlq-manager';
|
|
4
|
+
import { QueueManager } from './queue-manager';
|
|
5
|
+
import type { BullMQEventAdapterConfig } from './types';
|
|
6
|
+
import { WorkerManager } from './worker-manager';
|
|
7
|
+
export declare class BullMQEventAdapter implements EventAdapter {
|
|
8
|
+
private readonly connectionManager;
|
|
9
|
+
private readonly _queueManager;
|
|
10
|
+
private readonly _workerManager;
|
|
11
|
+
private readonly _dlqManager;
|
|
12
|
+
private readonly _config;
|
|
13
|
+
constructor(config: BullMQEventAdapterConfig);
|
|
14
|
+
get connection(): Redis;
|
|
15
|
+
get prefix(): string;
|
|
16
|
+
get dlqSuffix(): string;
|
|
17
|
+
get queueManager(): QueueManager;
|
|
18
|
+
get workerManager(): WorkerManager;
|
|
19
|
+
get dlqManager(): DLQManager;
|
|
20
|
+
emit<TData>(event: Event<TData>): Promise<void>;
|
|
21
|
+
subscribe<TData>(topic: string, stepName: string, handler: (event: Event<TData>) => void | Promise<void>, options?: QueueConfig): Promise<SubscriptionHandle>;
|
|
22
|
+
unsubscribe(handle: SubscriptionHandle): Promise<void>;
|
|
23
|
+
shutdown(): Promise<void>;
|
|
24
|
+
getSubscriptionCount(topic: string): Promise<number>;
|
|
25
|
+
listTopics(): Promise<string[]>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=bullmq-event-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bullmq-event-adapter.d.ts","sourceRoot":"","sources":["../src/bullmq-event-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAC1F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,qBAAa,kBAAmB,YAAW,YAAY;IACrD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAY;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;gBAE1B,MAAM,EAAE,wBAAwB;IAa5C,IAAI,UAAU,IAAI,KAAK,CAEtB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,YAAY,IAAI,YAAY,CAE/B;IAED,IAAI,aAAa,IAAI,aAAa,CAEjC;IAED,IAAI,UAAU,IAAI,UAAU,CAE3B;IAEK,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/C,SAAS,CAAC,KAAK,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EACtD,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,kBAAkB,CAAC;IAOxB,WAAW,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAStD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAczB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpD,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAGtC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BullMQEventAdapter = void 0;
|
|
4
|
+
const config_builder_1 = require("./config-builder");
|
|
5
|
+
const connection_manager_1 = require("./connection-manager");
|
|
6
|
+
const dlq_manager_1 = require("./dlq-manager");
|
|
7
|
+
const queue_manager_1 = require("./queue-manager");
|
|
8
|
+
const worker_manager_1 = require("./worker-manager");
|
|
9
|
+
class BullMQEventAdapter {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this._config = (0, config_builder_1.buildConfig)(config);
|
|
12
|
+
this.connectionManager = new connection_manager_1.ConnectionManager(config.connection);
|
|
13
|
+
this._queueManager = new queue_manager_1.QueueManager(this.connectionManager.connection, this._config);
|
|
14
|
+
this._dlqManager = new dlq_manager_1.DLQManager(this.connectionManager.connection, this._config);
|
|
15
|
+
this._workerManager = new worker_manager_1.WorkerManager(this.connectionManager.connection, this._config, (topic, stepName) => this._queueManager.getQueueName(topic, stepName), this._dlqManager);
|
|
16
|
+
}
|
|
17
|
+
get connection() {
|
|
18
|
+
return this.connectionManager.connection;
|
|
19
|
+
}
|
|
20
|
+
get prefix() {
|
|
21
|
+
return this._config.prefix;
|
|
22
|
+
}
|
|
23
|
+
get dlqSuffix() {
|
|
24
|
+
return this._config.dlq.suffix;
|
|
25
|
+
}
|
|
26
|
+
get queueManager() {
|
|
27
|
+
return this._queueManager;
|
|
28
|
+
}
|
|
29
|
+
get workerManager() {
|
|
30
|
+
return this._workerManager;
|
|
31
|
+
}
|
|
32
|
+
get dlqManager() {
|
|
33
|
+
return this._dlqManager;
|
|
34
|
+
}
|
|
35
|
+
async emit(event) {
|
|
36
|
+
const subscribers = this._workerManager.getSubscribers(event.topic);
|
|
37
|
+
if (subscribers.length === 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
await this._queueManager.enqueueToAll(event, subscribers);
|
|
41
|
+
}
|
|
42
|
+
async subscribe(topic, stepName, handler, options) {
|
|
43
|
+
const queueName = this._queueManager.getQueueName(topic, stepName);
|
|
44
|
+
this._queueManager.getQueue(queueName);
|
|
45
|
+
return this._workerManager.createWorker(topic, stepName, handler, options);
|
|
46
|
+
}
|
|
47
|
+
async unsubscribe(handle) {
|
|
48
|
+
const workerInfo = this._workerManager.getWorkerInfo(handle.id);
|
|
49
|
+
if (workerInfo) {
|
|
50
|
+
const queueName = this._queueManager.getQueueName(workerInfo.topic, workerInfo.stepName);
|
|
51
|
+
await this._queueManager.closeQueue(queueName);
|
|
52
|
+
await this._workerManager.removeWorker(handle.id);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async shutdown() {
|
|
56
|
+
await Promise.allSettled([
|
|
57
|
+
this._workerManager.closeAll(),
|
|
58
|
+
this._queueManager.closeAll(),
|
|
59
|
+
this._dlqManager.closeAll(),
|
|
60
|
+
]);
|
|
61
|
+
try {
|
|
62
|
+
await this.connectionManager.close();
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.error('[BullMQ] Error closing connection:', err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async getSubscriptionCount(topic) {
|
|
69
|
+
return this._workerManager.getSubscriptionCount(topic);
|
|
70
|
+
}
|
|
71
|
+
async listTopics() {
|
|
72
|
+
return this._workerManager.listTopics();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.BullMQEventAdapter = BullMQEventAdapter;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BullMQEventAdapterConfig } from './types';
|
|
2
|
+
export type MergedConfig = Required<Pick<BullMQEventAdapterConfig, 'defaultJobOptions' | 'prefix' | 'concurrency'>> & {
|
|
3
|
+
dlq: Required<NonNullable<BullMQEventAdapterConfig['dlq']>>;
|
|
4
|
+
};
|
|
5
|
+
export declare function buildConfig(config: BullMQEventAdapterConfig): MergedConfig;
|
|
6
|
+
//# sourceMappingURL=config-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-builder.d.ts","sourceRoot":"","sources":["../src/config-builder.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,wBAAwB,EAAE,mBAAmB,GAAG,QAAQ,GAAG,aAAa,CAAC,CAAC,GAAG;IACpH,GAAG,EAAE,QAAQ,CAAC,WAAW,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;CAC5D,CAAA;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,wBAAwB,GAAG,YAAY,CAwB1E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildConfig = buildConfig;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
function buildConfig(config) {
|
|
6
|
+
return {
|
|
7
|
+
concurrency: config.concurrency ?? constants_1.DEFAULT_CONCURRENCY,
|
|
8
|
+
defaultJobOptions: {
|
|
9
|
+
attempts: constants_1.DEFAULT_ATTEMPTS,
|
|
10
|
+
backoff: {
|
|
11
|
+
type: 'fixed',
|
|
12
|
+
delay: constants_1.DEFAULT_BACKOFF_DELAY,
|
|
13
|
+
},
|
|
14
|
+
removeOnComplete: {
|
|
15
|
+
count: constants_1.DEFAULT_REMOVE_ON_COMPLETE_COUNT,
|
|
16
|
+
},
|
|
17
|
+
removeOnFail: {
|
|
18
|
+
count: constants_1.DEFAULT_REMOVE_ON_FAIL_COUNT,
|
|
19
|
+
},
|
|
20
|
+
...config.defaultJobOptions,
|
|
21
|
+
},
|
|
22
|
+
prefix: config.prefix ?? constants_1.DEFAULT_PREFIX,
|
|
23
|
+
dlq: {
|
|
24
|
+
enabled: config.dlq?.enabled ?? true,
|
|
25
|
+
ttl: config.dlq?.ttl ?? constants_1.DEFAULT_DLQ_TTL,
|
|
26
|
+
suffix: config.dlq?.suffix ?? constants_1.DEFAULT_DLQ_SUFFIX,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Redis } from 'ioredis';
|
|
2
|
+
import type { BullMQConnectionConfig } from './types';
|
|
3
|
+
export declare class ConnectionManager {
|
|
4
|
+
readonly connection: Redis;
|
|
5
|
+
readonly ownsConnection: boolean;
|
|
6
|
+
constructor(config: BullMQConnectionConfig);
|
|
7
|
+
private setupEventHandlers;
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=connection-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../src/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAA;IAC1B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;gBAEpB,MAAM,EAAE,sBAAsB;IAe1C,OAAO,CAAC,kBAAkB;IAWpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConnectionManager = void 0;
|
|
7
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
class ConnectionManager {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
if (config instanceof ioredis_1.default) {
|
|
12
|
+
this.connection = config;
|
|
13
|
+
this.ownsConnection = false;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.connection = new ioredis_1.default({
|
|
17
|
+
maxRetriesPerRequest: null,
|
|
18
|
+
...config,
|
|
19
|
+
});
|
|
20
|
+
this.ownsConnection = true;
|
|
21
|
+
}
|
|
22
|
+
this.setupEventHandlers();
|
|
23
|
+
}
|
|
24
|
+
setupEventHandlers() {
|
|
25
|
+
this.connection.on('error', (err) => {
|
|
26
|
+
const error = new errors_1.ConnectionError(err.message, err);
|
|
27
|
+
console.error('[BullMQ] Connection error:', error);
|
|
28
|
+
});
|
|
29
|
+
this.connection.on('close', () => {
|
|
30
|
+
console.warn('[BullMQ] Connection closed');
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async close() {
|
|
34
|
+
if (this.ownsConnection && this.connection.status !== 'end') {
|
|
35
|
+
await this.connection.quit();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ConnectionManager = ConnectionManager;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const DEFAULT_CONCURRENCY = 5;
|
|
2
|
+
export declare const DEFAULT_ATTEMPTS = 3;
|
|
3
|
+
export declare const DEFAULT_BACKOFF_DELAY = 2000;
|
|
4
|
+
export declare const DEFAULT_REMOVE_ON_COMPLETE_COUNT = 1000;
|
|
5
|
+
export declare const DEFAULT_REMOVE_ON_FAIL_COUNT = 5000;
|
|
6
|
+
export declare const DEFAULT_PREFIX = "motia";
|
|
7
|
+
export declare const FIFO_CONCURRENCY = 1;
|
|
8
|
+
export declare const MILLISECONDS_PER_SECOND = 1000;
|
|
9
|
+
export declare const SECONDS_PER_DAY = 86400;
|
|
10
|
+
export declare const DEFAULT_DLQ_TTL: number;
|
|
11
|
+
export declare const DEFAULT_DLQ_SUFFIX = ".dlq";
|
|
12
|
+
export declare const DLQ_JOB_PREFIX = "dlq-";
|
|
13
|
+
export declare const LOG_PREFIX = "[BullMQ]";
|
|
14
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,qBAAqB,OAAO,CAAA;AACzC,eAAO,MAAM,gCAAgC,OAAO,CAAA;AACpD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAChD,eAAO,MAAM,cAAc,UAAU,CAAA;AACrC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,uBAAuB,OAAO,CAAA;AAC3C,eAAO,MAAM,eAAe,QAAQ,CAAA;AACpC,eAAO,MAAM,eAAe,QAAuB,CAAA;AACnD,eAAO,MAAM,kBAAkB,SAAS,CAAA;AACxC,eAAO,MAAM,cAAc,SAAS,CAAA;AAEpC,eAAO,MAAM,UAAU,aAAa,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_PREFIX = exports.DLQ_JOB_PREFIX = exports.DEFAULT_DLQ_SUFFIX = exports.DEFAULT_DLQ_TTL = exports.SECONDS_PER_DAY = exports.MILLISECONDS_PER_SECOND = exports.FIFO_CONCURRENCY = exports.DEFAULT_PREFIX = exports.DEFAULT_REMOVE_ON_FAIL_COUNT = exports.DEFAULT_REMOVE_ON_COMPLETE_COUNT = exports.DEFAULT_BACKOFF_DELAY = exports.DEFAULT_ATTEMPTS = exports.DEFAULT_CONCURRENCY = void 0;
|
|
4
|
+
exports.DEFAULT_CONCURRENCY = 5;
|
|
5
|
+
exports.DEFAULT_ATTEMPTS = 3;
|
|
6
|
+
exports.DEFAULT_BACKOFF_DELAY = 2000;
|
|
7
|
+
exports.DEFAULT_REMOVE_ON_COMPLETE_COUNT = 1000;
|
|
8
|
+
exports.DEFAULT_REMOVE_ON_FAIL_COUNT = 5000;
|
|
9
|
+
exports.DEFAULT_PREFIX = 'motia';
|
|
10
|
+
exports.FIFO_CONCURRENCY = 1;
|
|
11
|
+
exports.MILLISECONDS_PER_SECOND = 1000;
|
|
12
|
+
exports.SECONDS_PER_DAY = 86400;
|
|
13
|
+
exports.DEFAULT_DLQ_TTL = 30 * exports.SECONDS_PER_DAY;
|
|
14
|
+
exports.DEFAULT_DLQ_SUFFIX = '.dlq';
|
|
15
|
+
exports.DLQ_JOB_PREFIX = 'dlq-';
|
|
16
|
+
exports.LOG_PREFIX = '[BullMQ]';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Event } from '@motiadev/core';
|
|
2
|
+
import { Queue } from 'bullmq';
|
|
3
|
+
import type { Redis } from 'ioredis';
|
|
4
|
+
import type { MergedConfig } from './config-builder';
|
|
5
|
+
export declare class DLQManager {
|
|
6
|
+
private readonly dlqQueues;
|
|
7
|
+
private readonly connection;
|
|
8
|
+
private readonly config;
|
|
9
|
+
constructor(connection: Redis, config: MergedConfig);
|
|
10
|
+
getDLQQueueName(topic: string, stepName: string): string;
|
|
11
|
+
private getOrCreateDLQQueue;
|
|
12
|
+
moveToDLQ<TData>(topic: string, stepName: string, event: Event<TData>, error: Error, attemptsMade: number, originalJobId?: string): Promise<void>;
|
|
13
|
+
closeDLQQueue(queueName: string): Promise<void>;
|
|
14
|
+
closeAll(): Promise<void>;
|
|
15
|
+
getDLQQueue(queueName: string): Queue | undefined;
|
|
16
|
+
getOrCreateDLQ(queueName: string): Queue;
|
|
17
|
+
listDLQQueueNames(): string[];
|
|
18
|
+
getDLQSuffix(): string;
|
|
19
|
+
getPrefix(): string;
|
|
20
|
+
getConnection(): Redis;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=dlq-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dlq-manager.d.ts","sourceRoot":"","sources":["../src/dlq-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAYpD,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAO;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY;IAKnD,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAKxD,OAAO,CAAC,mBAAmB;IA8BrB,SAAS,CAAC,KAAK,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EACnB,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;IA0CV,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ/C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAU/B,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAIjD,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK;IAIxC,iBAAiB,IAAI,MAAM,EAAE;IAI7B,YAAY,IAAI,MAAM;IAItB,SAAS,IAAI,MAAM;IAInB,aAAa,IAAI,KAAK;CAGvB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DLQManager = void 0;
|
|
4
|
+
const bullmq_1 = require("bullmq");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
class DLQManager {
|
|
8
|
+
constructor(connection, config) {
|
|
9
|
+
this.dlqQueues = new Map();
|
|
10
|
+
this.connection = connection;
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
getDLQQueueName(topic, stepName) {
|
|
14
|
+
const baseQueueName = `${topic}.${stepName}`;
|
|
15
|
+
return `${baseQueueName}${this.config.dlq.suffix}`;
|
|
16
|
+
}
|
|
17
|
+
getOrCreateDLQQueue(queueName) {
|
|
18
|
+
if (!this.dlqQueues.has(queueName)) {
|
|
19
|
+
const ttlMs = this.config.dlq.ttl * constants_1.MILLISECONDS_PER_SECOND;
|
|
20
|
+
const queue = new bullmq_1.Queue(queueName, {
|
|
21
|
+
connection: this.connection,
|
|
22
|
+
prefix: this.config.prefix,
|
|
23
|
+
defaultJobOptions: {
|
|
24
|
+
removeOnComplete: {
|
|
25
|
+
age: ttlMs,
|
|
26
|
+
},
|
|
27
|
+
removeOnFail: {
|
|
28
|
+
age: ttlMs,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
queue.on('error', (err) => {
|
|
33
|
+
console.error(`${constants_1.LOG_PREFIX} DLQ error for ${queueName}:`, err);
|
|
34
|
+
});
|
|
35
|
+
this.dlqQueues.set(queueName, queue);
|
|
36
|
+
}
|
|
37
|
+
const queue = this.dlqQueues.get(queueName);
|
|
38
|
+
if (!queue) {
|
|
39
|
+
throw new errors_1.QueueCreationError(queueName);
|
|
40
|
+
}
|
|
41
|
+
return queue;
|
|
42
|
+
}
|
|
43
|
+
async moveToDLQ(topic, stepName, event, error, attemptsMade, originalJobId) {
|
|
44
|
+
if (!this.config.dlq.enabled) {
|
|
45
|
+
console.warn(`${constants_1.LOG_PREFIX} DLQ is disabled, skipping move to DLQ for topic ${topic}, step ${stepName}`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const dlqQueueName = this.getDLQQueueName(topic, stepName);
|
|
50
|
+
const dlqQueue = this.getOrCreateDLQQueue(dlqQueueName);
|
|
51
|
+
const sanitizedEvent = {
|
|
52
|
+
topic: event.topic,
|
|
53
|
+
data: event.data,
|
|
54
|
+
traceId: event.traceId || 'unknown',
|
|
55
|
+
...(event.flows && { flows: event.flows }),
|
|
56
|
+
...(event.messageGroupId && { messageGroupId: event.messageGroupId }),
|
|
57
|
+
};
|
|
58
|
+
const dlqJobData = {
|
|
59
|
+
originalEvent: sanitizedEvent,
|
|
60
|
+
failureReason: error.message || 'Unknown error',
|
|
61
|
+
failureTimestamp: Date.now(),
|
|
62
|
+
attemptsMade,
|
|
63
|
+
...(originalJobId && { originalJobId }),
|
|
64
|
+
};
|
|
65
|
+
const jobOptions = originalJobId ? { jobId: `${constants_1.DLQ_JOB_PREFIX}${originalJobId}` } : {};
|
|
66
|
+
await dlqQueue.add(`${topic}.dlq`, dlqJobData, jobOptions);
|
|
67
|
+
console.warn(`${constants_1.LOG_PREFIX} Moved failed job to DLQ: ${dlqQueueName}`, {
|
|
68
|
+
topic,
|
|
69
|
+
stepName,
|
|
70
|
+
attemptsMade,
|
|
71
|
+
error: error.message,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
const dlqError = err instanceof Error ? err : new Error(String(err));
|
|
76
|
+
console.error(`${constants_1.LOG_PREFIX} Failed to move job to DLQ for topic ${topic}, step ${stepName}:`, dlqError);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async closeDLQQueue(queueName) {
|
|
80
|
+
const queue = this.dlqQueues.get(queueName);
|
|
81
|
+
if (queue) {
|
|
82
|
+
await queue.close();
|
|
83
|
+
this.dlqQueues.delete(queueName);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async closeAll() {
|
|
87
|
+
const promises = Array.from(this.dlqQueues.values()).map((queue) => queue.close().catch((err) => {
|
|
88
|
+
console.error(`${constants_1.LOG_PREFIX} Error closing DLQ queue:`, err);
|
|
89
|
+
}));
|
|
90
|
+
await Promise.allSettled(promises);
|
|
91
|
+
this.dlqQueues.clear();
|
|
92
|
+
}
|
|
93
|
+
getDLQQueue(queueName) {
|
|
94
|
+
return this.dlqQueues.get(queueName);
|
|
95
|
+
}
|
|
96
|
+
getOrCreateDLQ(queueName) {
|
|
97
|
+
return this.getOrCreateDLQQueue(queueName);
|
|
98
|
+
}
|
|
99
|
+
listDLQQueueNames() {
|
|
100
|
+
return Array.from(this.dlqQueues.keys());
|
|
101
|
+
}
|
|
102
|
+
getDLQSuffix() {
|
|
103
|
+
return this.config.dlq.suffix;
|
|
104
|
+
}
|
|
105
|
+
getPrefix() {
|
|
106
|
+
return this.config.prefix;
|
|
107
|
+
}
|
|
108
|
+
getConnection() {
|
|
109
|
+
return this.connection;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.DLQManager = DLQManager;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class BullMQAdapterError extends Error {
|
|
2
|
+
readonly cause?: Error | undefined;
|
|
3
|
+
constructor(message: string, cause?: Error | undefined);
|
|
4
|
+
}
|
|
5
|
+
export declare class QueueCreationError extends BullMQAdapterError {
|
|
6
|
+
constructor(queueName: string, cause?: Error);
|
|
7
|
+
}
|
|
8
|
+
export declare class WorkerCreationError extends BullMQAdapterError {
|
|
9
|
+
constructor(topic: string, stepName: string, cause?: Error);
|
|
10
|
+
}
|
|
11
|
+
export declare class ConnectionError extends BullMQAdapterError {
|
|
12
|
+
constructor(message: string, cause?: Error);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;aAGzB,KAAK,CAAC,EAAE,KAAK;gBAD7B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,KAAK,YAAA;CAQhC;AAED,qBAAa,kBAAmB,SAAQ,kBAAkB;gBAC5C,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI7C;AAED,qBAAa,mBAAoB,SAAQ,kBAAkB;gBAC7C,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3D;AAED,qBAAa,eAAgB,SAAQ,kBAAkB;gBACzC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionError = exports.WorkerCreationError = exports.QueueCreationError = exports.BullMQAdapterError = void 0;
|
|
4
|
+
class BullMQAdapterError extends Error {
|
|
5
|
+
constructor(message, cause) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.cause = cause;
|
|
8
|
+
this.name = 'BullMQAdapterError';
|
|
9
|
+
if (cause) {
|
|
10
|
+
this.stack = `${this.stack}\nCaused by: ${cause.stack}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.BullMQAdapterError = BullMQAdapterError;
|
|
15
|
+
class QueueCreationError extends BullMQAdapterError {
|
|
16
|
+
constructor(queueName, cause) {
|
|
17
|
+
super(`Failed to create queue: ${queueName}`, cause);
|
|
18
|
+
this.name = 'QueueCreationError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.QueueCreationError = QueueCreationError;
|
|
22
|
+
class WorkerCreationError extends BullMQAdapterError {
|
|
23
|
+
constructor(topic, stepName, cause) {
|
|
24
|
+
super(`Failed to create worker for topic ${topic}, step ${stepName}`, cause);
|
|
25
|
+
this.name = 'WorkerCreationError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.WorkerCreationError = WorkerCreationError;
|
|
29
|
+
class ConnectionError extends BullMQAdapterError {
|
|
30
|
+
constructor(message, cause) {
|
|
31
|
+
super(`Connection error: ${message}`, cause);
|
|
32
|
+
this.name = 'ConnectionError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ConnectionError = ConnectionError;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BullMQEventAdapter } from './bullmq-event-adapter';
|
|
2
|
+
export { DLQManager } from './dlq-manager';
|
|
3
|
+
export { QueueManager } from './queue-manager';
|
|
4
|
+
export type { BullMQConnectionConfig, BullMQEventAdapterConfig } from './types';
|
|
5
|
+
export type { SubscriberInfo } from './worker-manager';
|
|
6
|
+
export { WorkerManager } from './worker-manager';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAC/E,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerManager = exports.QueueManager = exports.DLQManager = exports.BullMQEventAdapter = void 0;
|
|
4
|
+
var bullmq_event_adapter_1 = require("./bullmq-event-adapter");
|
|
5
|
+
Object.defineProperty(exports, "BullMQEventAdapter", { enumerable: true, get: function () { return bullmq_event_adapter_1.BullMQEventAdapter; } });
|
|
6
|
+
var dlq_manager_1 = require("./dlq-manager");
|
|
7
|
+
Object.defineProperty(exports, "DLQManager", { enumerable: true, get: function () { return dlq_manager_1.DLQManager; } });
|
|
8
|
+
var queue_manager_1 = require("./queue-manager");
|
|
9
|
+
Object.defineProperty(exports, "QueueManager", { enumerable: true, get: function () { return queue_manager_1.QueueManager; } });
|
|
10
|
+
var worker_manager_1 = require("./worker-manager");
|
|
11
|
+
Object.defineProperty(exports, "WorkerManager", { enumerable: true, get: function () { return worker_manager_1.WorkerManager; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Event } from '@motiadev/core';
|
|
2
|
+
import { Queue } from 'bullmq';
|
|
3
|
+
import type { Redis } from 'ioredis';
|
|
4
|
+
import type { MergedConfig } from './config-builder';
|
|
5
|
+
import type { SubscriberInfo } from './worker-manager';
|
|
6
|
+
export declare class QueueManager {
|
|
7
|
+
private readonly queues;
|
|
8
|
+
private readonly connection;
|
|
9
|
+
private readonly config;
|
|
10
|
+
constructor(connection: Redis, config: MergedConfig);
|
|
11
|
+
getQueue(queueName: string): Queue;
|
|
12
|
+
getQueueName(topic: string, stepName: string): string;
|
|
13
|
+
enqueueToAll<TData>(event: Event<TData>, subscribers: SubscriberInfo[]): Promise<void>;
|
|
14
|
+
closeQueue(queueName: string): Promise<void>;
|
|
15
|
+
closeAll(): Promise<void>;
|
|
16
|
+
listQueueNames(): string[];
|
|
17
|
+
getPrefix(): string;
|
|
18
|
+
getConnection(): Redis;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=queue-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-manager.d.ts","sourceRoot":"","sources":["../src/queue-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAO;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY;IAKnD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK;IAsBlC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI/C,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCtF,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAU/B,cAAc,IAAI,MAAM,EAAE;IAI1B,SAAS,IAAI,MAAM;IAInB,aAAa,IAAI,KAAK;CAGvB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueueManager = void 0;
|
|
4
|
+
const bullmq_1 = require("bullmq");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
class QueueManager {
|
|
8
|
+
constructor(connection, config) {
|
|
9
|
+
this.queues = new Map();
|
|
10
|
+
this.connection = connection;
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
getQueue(queueName) {
|
|
14
|
+
if (!this.queues.has(queueName)) {
|
|
15
|
+
const queue = new bullmq_1.Queue(queueName, {
|
|
16
|
+
connection: this.connection,
|
|
17
|
+
prefix: this.config.prefix,
|
|
18
|
+
defaultJobOptions: this.config.defaultJobOptions,
|
|
19
|
+
});
|
|
20
|
+
queue.on('error', (err) => {
|
|
21
|
+
console.error(`[BullMQ] Queue error for ${queueName}:`, err);
|
|
22
|
+
});
|
|
23
|
+
this.queues.set(queueName, queue);
|
|
24
|
+
}
|
|
25
|
+
const queue = this.queues.get(queueName);
|
|
26
|
+
if (!queue) {
|
|
27
|
+
throw new errors_1.QueueCreationError(queueName);
|
|
28
|
+
}
|
|
29
|
+
return queue;
|
|
30
|
+
}
|
|
31
|
+
getQueueName(topic, stepName) {
|
|
32
|
+
return `${topic}.${stepName}`;
|
|
33
|
+
}
|
|
34
|
+
async enqueueToAll(event, subscribers) {
|
|
35
|
+
const promises = subscribers.map((subscriber) => {
|
|
36
|
+
const queueName = this.getQueueName(subscriber.topic, subscriber.stepName);
|
|
37
|
+
const queue = this.getQueue(queueName);
|
|
38
|
+
const jobId = event.messageGroupId ? `${queueName}.${event.messageGroupId}` : undefined;
|
|
39
|
+
const jobData = {
|
|
40
|
+
topic: event.topic,
|
|
41
|
+
data: event.data,
|
|
42
|
+
traceId: event.traceId,
|
|
43
|
+
flows: event.flows,
|
|
44
|
+
messageGroupId: event.messageGroupId,
|
|
45
|
+
};
|
|
46
|
+
const maxRetries = subscriber.queueConfig?.maxRetries;
|
|
47
|
+
const attempts = maxRetries != null ? maxRetries + 1 : this.config.defaultJobOptions.attempts;
|
|
48
|
+
const delay = subscriber.queueConfig?.delaySeconds
|
|
49
|
+
? subscriber.queueConfig.delaySeconds * constants_1.MILLISECONDS_PER_SECOND
|
|
50
|
+
: undefined;
|
|
51
|
+
const jobOptions = {
|
|
52
|
+
jobId,
|
|
53
|
+
attempts,
|
|
54
|
+
backoff: this.config.defaultJobOptions.backoff,
|
|
55
|
+
delay,
|
|
56
|
+
};
|
|
57
|
+
return queue.add(event.topic, jobData, jobOptions).then(() => undefined);
|
|
58
|
+
});
|
|
59
|
+
await Promise.all(promises);
|
|
60
|
+
}
|
|
61
|
+
async closeQueue(queueName) {
|
|
62
|
+
const queue = this.queues.get(queueName);
|
|
63
|
+
if (queue) {
|
|
64
|
+
await queue.close();
|
|
65
|
+
this.queues.delete(queueName);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async closeAll() {
|
|
69
|
+
const promises = Array.from(this.queues.values()).map((queue) => queue.close().catch((err) => {
|
|
70
|
+
console.error(`[BullMQ] Error closing queue:`, err);
|
|
71
|
+
}));
|
|
72
|
+
await Promise.allSettled(promises);
|
|
73
|
+
this.queues.clear();
|
|
74
|
+
}
|
|
75
|
+
listQueueNames() {
|
|
76
|
+
return Array.from(this.queues.keys());
|
|
77
|
+
}
|
|
78
|
+
getPrefix() {
|
|
79
|
+
return this.config.prefix;
|
|
80
|
+
}
|
|
81
|
+
getConnection() {
|
|
82
|
+
return this.connection;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.QueueManager = QueueManager;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { KeepJobs } from 'bullmq';
|
|
2
|
+
import type { Redis, RedisOptions } from 'ioredis';
|
|
3
|
+
export type BullMQConnectionConfig = Redis | RedisOptions;
|
|
4
|
+
export interface BullMQEventAdapterConfig {
|
|
5
|
+
connection: BullMQConnectionConfig;
|
|
6
|
+
concurrency?: number;
|
|
7
|
+
defaultJobOptions?: {
|
|
8
|
+
attempts?: number;
|
|
9
|
+
backoff?: {
|
|
10
|
+
type: 'fixed' | 'exponential';
|
|
11
|
+
delay: number;
|
|
12
|
+
};
|
|
13
|
+
removeOnComplete?: KeepJobs;
|
|
14
|
+
removeOnFail?: KeepJobs;
|
|
15
|
+
};
|
|
16
|
+
prefix?: string;
|
|
17
|
+
dlq?: {
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
ttl?: number;
|
|
20
|
+
suffix?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,YAAY,CAAA;AAEzD,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,sBAAsB,CAAA;IAClC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iBAAiB,CAAC,EAAE;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,OAAO,CAAC,EAAE;YACR,IAAI,EAAE,OAAO,GAAG,aAAa,CAAA;YAC7B,KAAK,EAAE,MAAM,CAAA;SACd,CAAA;QACD,gBAAgB,CAAC,EAAE,QAAQ,CAAA;QAC3B,YAAY,CAAC,EAAE,QAAQ,CAAA;KACxB,CAAA;IACD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE;QACJ,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Event, QueueConfig, SubscriptionHandle } from '@motiadev/core';
|
|
2
|
+
import { Worker } from 'bullmq';
|
|
3
|
+
import type { Redis } from 'ioredis';
|
|
4
|
+
import type { MergedConfig } from './config-builder';
|
|
5
|
+
import type { DLQManager } from './dlq-manager';
|
|
6
|
+
export type SubscriberInfo = {
|
|
7
|
+
topic: string;
|
|
8
|
+
stepName: string;
|
|
9
|
+
queueConfig?: QueueConfig;
|
|
10
|
+
};
|
|
11
|
+
type WorkerInfo = {
|
|
12
|
+
worker: Worker;
|
|
13
|
+
topic: string;
|
|
14
|
+
stepName: string;
|
|
15
|
+
handle: SubscriptionHandle;
|
|
16
|
+
queueConfig?: QueueConfig;
|
|
17
|
+
};
|
|
18
|
+
export declare class WorkerManager {
|
|
19
|
+
private readonly workers;
|
|
20
|
+
private readonly topicSubscriptions;
|
|
21
|
+
private readonly connection;
|
|
22
|
+
private readonly config;
|
|
23
|
+
private readonly getQueueName;
|
|
24
|
+
private readonly dlqManager;
|
|
25
|
+
constructor(connection: Redis, config: MergedConfig, getQueueName: (topic: string, stepName: string) => string, dlqManager?: DLQManager);
|
|
26
|
+
createWorker<TData>(topic: string, stepName: string, handler: (event: Event<TData>) => void | Promise<void>, options?: QueueConfig): SubscriptionHandle;
|
|
27
|
+
getSubscribers(topic: string): SubscriberInfo[];
|
|
28
|
+
getWorkerInfo(id: string): WorkerInfo | undefined;
|
|
29
|
+
removeWorker(id: string): Promise<void>;
|
|
30
|
+
closeAll(): Promise<void>;
|
|
31
|
+
getSubscriptionCount(topic: string): number;
|
|
32
|
+
listTopics(): string[];
|
|
33
|
+
private addTopicSubscription;
|
|
34
|
+
private removeTopicSubscription;
|
|
35
|
+
private setupWorkerHandlers;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=worker-manager.d.ts.map
|