@riktajs/queue 0.1.0
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/README.md +476 -0
- package/dist/config/queue.config.d.ts +137 -0
- package/dist/config/queue.config.d.ts.map +1 -0
- package/dist/config/queue.config.js +82 -0
- package/dist/config/queue.config.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +37 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/events.decorator.d.ts +85 -0
- package/dist/decorators/events.decorator.d.ts.map +1 -0
- package/dist/decorators/events.decorator.js +120 -0
- package/dist/decorators/events.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +8 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +8 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/process.decorator.d.ts +41 -0
- package/dist/decorators/process.decorator.d.ts.map +1 -0
- package/dist/decorators/process.decorator.js +61 -0
- package/dist/decorators/process.decorator.js.map +1 -0
- package/dist/decorators/processor.decorator.d.ts +41 -0
- package/dist/decorators/processor.decorator.d.ts.map +1 -0
- package/dist/decorators/processor.decorator.js +59 -0
- package/dist/decorators/processor.decorator.js.map +1 -0
- package/dist/decorators/queue.decorator.d.ts +35 -0
- package/dist/decorators/queue.decorator.d.ts.map +1 -0
- package/dist/decorators/queue.decorator.js +49 -0
- package/dist/decorators/queue.decorator.js.map +1 -0
- package/dist/events/queue-events.d.ts +32 -0
- package/dist/events/queue-events.d.ts.map +1 -0
- package/dist/events/queue-events.js +103 -0
- package/dist/events/queue-events.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/monitoring/bull-board.d.ts +77 -0
- package/dist/monitoring/bull-board.d.ts.map +1 -0
- package/dist/monitoring/bull-board.js +112 -0
- package/dist/monitoring/bull-board.js.map +1 -0
- package/dist/providers/queue.provider.d.ts +94 -0
- package/dist/providers/queue.provider.d.ts.map +1 -0
- package/dist/providers/queue.provider.js +333 -0
- package/dist/providers/queue.provider.js.map +1 -0
- package/dist/services/queue.service.d.ts +133 -0
- package/dist/services/queue.service.d.ts.map +1 -0
- package/dist/services/queue.service.js +192 -0
- package/dist/services/queue.service.js.map +1 -0
- package/dist/types.d.ts +133 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/connection.d.ts +47 -0
- package/dist/utils/connection.d.ts.map +1 -0
- package/dist/utils/connection.js +104 -0
- package/dist/utils/connection.js.map +1 -0
- package/dist/utils/validation.d.ts +187 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +156 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-events.d.ts","sourceRoot":"","sources":["../../src/events/queue-events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,mCAAmC;AACnC,MAAM,MAAM,cAAc,GACtB,WAAW,GACX,eAAe,GACf,YAAY,GACZ,cAAc,GACd,aAAa,GACb,aAAa,GACb,aAAa,GACb,cAAc,GACd,eAAe,GACf,cAAc,CAAC;AAEnB,wCAAwC;AACxC,eAAO,MAAM,YAAY;;;;;;;;;;;CAWf,CAAC;AAEX;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAyBlE;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,MAAM,EACjB,GAAG,IAAI,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queue events integration with Rikta's EventBus
|
|
3
|
+
*/
|
|
4
|
+
/** Event bus event names with prefix */
|
|
5
|
+
export const QUEUE_EVENTS = {
|
|
6
|
+
JOB_ADDED: 'queue:job:added',
|
|
7
|
+
JOB_COMPLETED: 'queue:job:completed',
|
|
8
|
+
JOB_FAILED: 'queue:job:failed',
|
|
9
|
+
JOB_PROGRESS: 'queue:job:progress',
|
|
10
|
+
JOB_STALLED: 'queue:job:stalled',
|
|
11
|
+
JOB_DELAYED: 'queue:job:delayed',
|
|
12
|
+
JOB_REMOVED: 'queue:job:removed',
|
|
13
|
+
WORKER_READY: 'queue:worker:ready',
|
|
14
|
+
WORKER_CLOSED: 'queue:worker:closed',
|
|
15
|
+
WORKER_ERROR: 'queue:worker:error',
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Map internal event names to EventBus event names
|
|
19
|
+
*/
|
|
20
|
+
export function getEventBusEventName(event) {
|
|
21
|
+
switch (event) {
|
|
22
|
+
case 'job:added':
|
|
23
|
+
return QUEUE_EVENTS.JOB_ADDED;
|
|
24
|
+
case 'job:completed':
|
|
25
|
+
return QUEUE_EVENTS.JOB_COMPLETED;
|
|
26
|
+
case 'job:failed':
|
|
27
|
+
return QUEUE_EVENTS.JOB_FAILED;
|
|
28
|
+
case 'job:progress':
|
|
29
|
+
return QUEUE_EVENTS.JOB_PROGRESS;
|
|
30
|
+
case 'job:stalled':
|
|
31
|
+
return QUEUE_EVENTS.JOB_STALLED;
|
|
32
|
+
case 'job:delayed':
|
|
33
|
+
return QUEUE_EVENTS.JOB_DELAYED;
|
|
34
|
+
case 'job:removed':
|
|
35
|
+
return QUEUE_EVENTS.JOB_REMOVED;
|
|
36
|
+
case 'worker:ready':
|
|
37
|
+
return QUEUE_EVENTS.WORKER_READY;
|
|
38
|
+
case 'worker:closed':
|
|
39
|
+
return QUEUE_EVENTS.WORKER_CLOSED;
|
|
40
|
+
case 'worker:error':
|
|
41
|
+
return QUEUE_EVENTS.WORKER_ERROR;
|
|
42
|
+
default:
|
|
43
|
+
return `queue:${event}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Publish a queue event to the EventBus
|
|
48
|
+
*
|
|
49
|
+
* @param eventBus - Rikta's EventBus instance
|
|
50
|
+
* @param event - The event name
|
|
51
|
+
* @param queueName - The queue name
|
|
52
|
+
* @param args - Event arguments (job, result, error, etc.)
|
|
53
|
+
*/
|
|
54
|
+
export async function publishQueueEvent(eventBus, event, queueName, ...args) {
|
|
55
|
+
if (!eventBus || typeof eventBus.emit !== 'function') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const eventName = getEventBusEventName(event);
|
|
59
|
+
const payload = createEventPayload(event, queueName, args);
|
|
60
|
+
await eventBus.emit(eventName, payload);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create an event payload from event arguments
|
|
64
|
+
*/
|
|
65
|
+
function createEventPayload(event, queueName, args) {
|
|
66
|
+
const base = {
|
|
67
|
+
queueName,
|
|
68
|
+
jobId: '',
|
|
69
|
+
jobName: '',
|
|
70
|
+
data: null,
|
|
71
|
+
timestamp: Date.now(),
|
|
72
|
+
};
|
|
73
|
+
const job = args[0];
|
|
74
|
+
if (typeof job === 'object' && job !== null) {
|
|
75
|
+
base.jobId = job.id || '';
|
|
76
|
+
base.jobName = job.name || '';
|
|
77
|
+
base.data = job.data;
|
|
78
|
+
}
|
|
79
|
+
else if (typeof job === 'string') {
|
|
80
|
+
// For stalled events, first arg is jobId
|
|
81
|
+
base.jobId = job;
|
|
82
|
+
}
|
|
83
|
+
switch (event) {
|
|
84
|
+
case 'job:completed':
|
|
85
|
+
base.returnValue = args[1];
|
|
86
|
+
break;
|
|
87
|
+
case 'job:failed':
|
|
88
|
+
base.error = args[1] instanceof Error
|
|
89
|
+
? args[1].message
|
|
90
|
+
: String(args[1]);
|
|
91
|
+
break;
|
|
92
|
+
case 'job:progress':
|
|
93
|
+
base.progress = args[1];
|
|
94
|
+
break;
|
|
95
|
+
case 'worker:error':
|
|
96
|
+
base.error = args[0] instanceof Error
|
|
97
|
+
? args[0].message
|
|
98
|
+
: String(args[0]);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
return base;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=queue-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-events.js","sourceRoot":"","sources":["../../src/events/queue-events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,wCAAwC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,SAAS,EAAE,iBAAiB;IAC5B,aAAa,EAAE,qBAAqB;IACpC,UAAU,EAAE,kBAAkB;IAC9B,YAAY,EAAE,oBAAoB;IAClC,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE,mBAAmB;IAChC,YAAY,EAAE,oBAAoB;IAClC,aAAa,EAAE,qBAAqB;IACpC,YAAY,EAAE,oBAAoB;CAC1B,CAAC;AAEX;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAqB;IACxD,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,WAAW;YACd,OAAO,YAAY,CAAC,SAAS,CAAC;QAChC,KAAK,eAAe;YAClB,OAAO,YAAY,CAAC,aAAa,CAAC;QACpC,KAAK,YAAY;YACf,OAAO,YAAY,CAAC,UAAU,CAAC;QACjC,KAAK,cAAc;YACjB,OAAO,YAAY,CAAC,YAAY,CAAC;QACnC,KAAK,aAAa;YAChB,OAAO,YAAY,CAAC,WAAW,CAAC;QAClC,KAAK,aAAa;YAChB,OAAO,YAAY,CAAC,WAAW,CAAC;QAClC,KAAK,aAAa;YAChB,OAAO,YAAY,CAAC,WAAW,CAAC;QAClC,KAAK,cAAc;YACjB,OAAO,YAAY,CAAC,YAAY,CAAC;QACnC,KAAK,eAAe;YAClB,OAAO,YAAY,CAAC,aAAa,CAAC;QACpC,KAAK,cAAc;YACjB,OAAO,YAAY,CAAC,YAAY,CAAC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ClB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3B,MAAM;QACR,KAAK,YAAY;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,KAAK;gBACnC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO;gBACjB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACpB,MAAM;QACR,KAAK,cAAc;YACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAoB,CAAC;YAC3C,MAAM;QACR,KAAK,cAAc;YACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,KAAK;gBACnC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO;gBACjB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACpB,MAAM;IACV,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/queue
|
|
3
|
+
*
|
|
4
|
+
* BullMQ-based job queue integration for Rikta Framework.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export * from './constants.js';
|
|
9
|
+
export * from './types.js';
|
|
10
|
+
export * from './config/queue.config.js';
|
|
11
|
+
export { Queue, getQueueOptions, isQueue, QueueDecoratorError, } from './decorators/queue.decorator.js';
|
|
12
|
+
export { Processor, getProcessorOptions, isProcessor, ProcessorDecoratorError, } from './decorators/processor.decorator.js';
|
|
13
|
+
export { Process, getJobHandlers, isJobHandler, } from './decorators/process.decorator.js';
|
|
14
|
+
export { OnJobComplete, OnJobFailed, OnJobProgress, OnJobStalled, OnWorkerReady, OnWorkerError, getEventHandlers, getEventHandlersFor, } from './decorators/events.decorator.js';
|
|
15
|
+
export * from './providers/queue.provider.js';
|
|
16
|
+
export * from './services/queue.service.js';
|
|
17
|
+
export { QUEUE_EVENTS, getEventBusEventName, publishQueueEvent, } from './events/queue-events.js';
|
|
18
|
+
export type { QueueEventName } from './events/queue-events.js';
|
|
19
|
+
export * from './monitoring/bull-board.js';
|
|
20
|
+
export * from './utils/connection.js';
|
|
21
|
+
export * from './utils/validation.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,YAAY,CAAC;AAG3B,cAAc,0BAA0B,CAAC;AAGzC,OAAO,EACL,KAAK,EACL,eAAe,EACf,OAAO,EACP,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,WAAW,EACX,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,OAAO,EACP,cAAc,EACd,YAAY,GACb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAG1C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,6BAA6B,CAAC;AAG5C,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,cAAc,4BAA4B,CAAC;AAG3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/queue
|
|
3
|
+
*
|
|
4
|
+
* BullMQ-based job queue integration for Rikta Framework.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
// Constants and tokens
|
|
9
|
+
export * from './constants.js';
|
|
10
|
+
// Types
|
|
11
|
+
export * from './types.js';
|
|
12
|
+
// Configuration
|
|
13
|
+
export * from './config/queue.config.js';
|
|
14
|
+
// Decorators
|
|
15
|
+
export { Queue, getQueueOptions, isQueue, QueueDecoratorError, } from './decorators/queue.decorator.js';
|
|
16
|
+
export { Processor, getProcessorOptions, isProcessor, ProcessorDecoratorError, } from './decorators/processor.decorator.js';
|
|
17
|
+
export { Process, getJobHandlers, isJobHandler, } from './decorators/process.decorator.js';
|
|
18
|
+
export { OnJobComplete, OnJobFailed, OnJobProgress, OnJobStalled, OnWorkerReady, OnWorkerError, getEventHandlers, getEventHandlersFor, } from './decorators/events.decorator.js';
|
|
19
|
+
// Providers
|
|
20
|
+
export * from './providers/queue.provider.js';
|
|
21
|
+
// Services
|
|
22
|
+
export * from './services/queue.service.js';
|
|
23
|
+
// Events
|
|
24
|
+
export { QUEUE_EVENTS, getEventBusEventName, publishQueueEvent, } from './events/queue-events.js';
|
|
25
|
+
// Monitoring (optional Bull Board integration)
|
|
26
|
+
export * from './monitoring/bull-board.js';
|
|
27
|
+
// Utils
|
|
28
|
+
export * from './utils/connection.js';
|
|
29
|
+
export * from './utils/validation.js';
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uBAAuB;AACvB,cAAc,gBAAgB,CAAC;AAE/B,QAAQ;AACR,cAAc,YAAY,CAAC;AAE3B,gBAAgB;AAChB,cAAc,0BAA0B,CAAC;AAEzC,aAAa;AACb,OAAO,EACL,KAAK,EACL,eAAe,EACf,OAAO,EACP,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,WAAW,EACX,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,OAAO,EACP,cAAc,EACd,YAAY,GACb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAE1C,YAAY;AACZ,cAAc,+BAA+B,CAAC;AAE9C,WAAW;AACX,cAAc,6BAA6B,CAAC;AAE5C,SAAS;AACT,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAGlC,+CAA+C;AAC/C,cAAc,4BAA4B,CAAC;AAE3C,QAAQ;AACR,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bull Board integration for queue monitoring
|
|
3
|
+
*
|
|
4
|
+
* This module provides optional Bull Board dashboard integration.
|
|
5
|
+
* Bull Board packages are NOT included as dependencies - install them separately:
|
|
6
|
+
*
|
|
7
|
+
* npm install @bull-board/api @bull-board/fastify
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { registerBullBoard } from '@riktajs/queue';
|
|
12
|
+
*
|
|
13
|
+
* // In your Rikta bootstrap:
|
|
14
|
+
* const app = await Rikta.create();
|
|
15
|
+
*
|
|
16
|
+
* // After queue provider is initialized:
|
|
17
|
+
* await registerBullBoard(app.server, {
|
|
18
|
+
* queues: queueProvider.getAllQueues(),
|
|
19
|
+
* path: '/admin/queues',
|
|
20
|
+
* auth: async (req) => {
|
|
21
|
+
* // Your auth logic here
|
|
22
|
+
* return req.headers.authorization === 'Bearer secret';
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { FastifyInstance, FastifyRequest } from 'fastify';
|
|
28
|
+
import type { Queue } from 'bullmq';
|
|
29
|
+
/** Options for Bull Board registration */
|
|
30
|
+
export interface BullBoardOptions {
|
|
31
|
+
/** Queues to display in the dashboard */
|
|
32
|
+
queues: Queue[];
|
|
33
|
+
/** Base path for the dashboard (default: '/admin/queues') */
|
|
34
|
+
path?: string;
|
|
35
|
+
/** Authentication function - return true to allow access */
|
|
36
|
+
auth?: (request: FastifyRequest) => boolean | Promise<boolean>;
|
|
37
|
+
/** Whether to use read-only mode */
|
|
38
|
+
readOnly?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Result of Bull Board registration */
|
|
41
|
+
export interface BullBoardResult {
|
|
42
|
+
/** The path where the dashboard is mounted */
|
|
43
|
+
path: string;
|
|
44
|
+
/** Function to add more queues dynamically */
|
|
45
|
+
addQueue: (queue: Queue) => void;
|
|
46
|
+
/** Function to remove a queue from the dashboard */
|
|
47
|
+
removeQueue: (queueName: string) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Register Bull Board dashboard with Fastify
|
|
51
|
+
*
|
|
52
|
+
* @param app - Fastify instance
|
|
53
|
+
* @param options - Dashboard configuration
|
|
54
|
+
* @returns Bull Board control object
|
|
55
|
+
*
|
|
56
|
+
* @throws BullBoardNotInstalledError if @bull-board packages are not installed
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const board = await registerBullBoard(app.server, {
|
|
61
|
+
* queues: queueProvider.getAllQueues(),
|
|
62
|
+
* path: '/admin/queues',
|
|
63
|
+
* auth: (req) => checkAdminAuth(req),
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Add more queues later
|
|
67
|
+
* board.addQueue(newQueue);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function registerBullBoard(app: FastifyInstance, options: BullBoardOptions): Promise<BullBoardResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Error thrown when Bull Board packages are not installed
|
|
73
|
+
*/
|
|
74
|
+
export declare class BullBoardNotInstalledError extends Error {
|
|
75
|
+
constructor();
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=bull-board.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bull-board.d.ts","sourceRoot":"","sources":["../../src/monitoring/bull-board.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEpC,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/D,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wCAAwC;AACxC,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,oDAAoD;IACpD,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA+D1B;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;;CAQpD"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bull Board integration for queue monitoring
|
|
3
|
+
*
|
|
4
|
+
* This module provides optional Bull Board dashboard integration.
|
|
5
|
+
* Bull Board packages are NOT included as dependencies - install them separately:
|
|
6
|
+
*
|
|
7
|
+
* npm install @bull-board/api @bull-board/fastify
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { registerBullBoard } from '@riktajs/queue';
|
|
12
|
+
*
|
|
13
|
+
* // In your Rikta bootstrap:
|
|
14
|
+
* const app = await Rikta.create();
|
|
15
|
+
*
|
|
16
|
+
* // After queue provider is initialized:
|
|
17
|
+
* await registerBullBoard(app.server, {
|
|
18
|
+
* queues: queueProvider.getAllQueues(),
|
|
19
|
+
* path: '/admin/queues',
|
|
20
|
+
* auth: async (req) => {
|
|
21
|
+
* // Your auth logic here
|
|
22
|
+
* return req.headers.authorization === 'Bearer secret';
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Register Bull Board dashboard with Fastify
|
|
29
|
+
*
|
|
30
|
+
* @param app - Fastify instance
|
|
31
|
+
* @param options - Dashboard configuration
|
|
32
|
+
* @returns Bull Board control object
|
|
33
|
+
*
|
|
34
|
+
* @throws BullBoardNotInstalledError if @bull-board packages are not installed
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const board = await registerBullBoard(app.server, {
|
|
39
|
+
* queues: queueProvider.getAllQueues(),
|
|
40
|
+
* path: '/admin/queues',
|
|
41
|
+
* auth: (req) => checkAdminAuth(req),
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Add more queues later
|
|
45
|
+
* board.addQueue(newQueue);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export async function registerBullBoard(app, options) {
|
|
49
|
+
const { queues, path = '/admin/queues', auth, readOnly = false } = options;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
let createBullBoard;
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
let BullMQAdapter;
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
let FastifyAdapter;
|
|
56
|
+
try {
|
|
57
|
+
// Dynamic imports - these will fail if packages not installed
|
|
58
|
+
// Use require for better compatibility
|
|
59
|
+
createBullBoard = require('@bull-board/api').createBullBoard;
|
|
60
|
+
FastifyAdapter = require('@bull-board/fastify').FastifyAdapter;
|
|
61
|
+
BullMQAdapter = require('@bull-board/api/bullMQAdapter').BullMQAdapter;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw new BullBoardNotInstalledError();
|
|
65
|
+
}
|
|
66
|
+
// Create adapters for all queues
|
|
67
|
+
const queueAdapters = queues.map(queue => new BullMQAdapter(queue, { readOnlyMode: readOnly }));
|
|
68
|
+
// Create the server adapter
|
|
69
|
+
const serverAdapter = new FastifyAdapter();
|
|
70
|
+
serverAdapter.setBasePath(path);
|
|
71
|
+
// Create Bull Board
|
|
72
|
+
const board = createBullBoard({
|
|
73
|
+
queues: queueAdapters,
|
|
74
|
+
serverAdapter,
|
|
75
|
+
});
|
|
76
|
+
// Add auth hook if provided
|
|
77
|
+
if (auth) {
|
|
78
|
+
app.addHook('preHandler', async (request, reply) => {
|
|
79
|
+
const url = request.url;
|
|
80
|
+
if (url.startsWith(path)) {
|
|
81
|
+
const isAuthorized = await auth(request);
|
|
82
|
+
if (!isAuthorized) {
|
|
83
|
+
reply.code(403).send({ error: 'Forbidden' });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Register the plugin
|
|
89
|
+
await app.register(serverAdapter.registerPlugin(), { basePath: path, prefix: path });
|
|
90
|
+
console.log(`📊 Bull Board: Dashboard available at ${path}`);
|
|
91
|
+
return {
|
|
92
|
+
path,
|
|
93
|
+
addQueue: (queue) => {
|
|
94
|
+
const adapter = new BullMQAdapter(queue, { readOnlyMode: readOnly });
|
|
95
|
+
board.addQueue(adapter);
|
|
96
|
+
},
|
|
97
|
+
removeQueue: (queueName) => {
|
|
98
|
+
board.removeQueue(queueName);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Error thrown when Bull Board packages are not installed
|
|
104
|
+
*/
|
|
105
|
+
export class BullBoardNotInstalledError extends Error {
|
|
106
|
+
constructor() {
|
|
107
|
+
super('Bull Board packages are not installed. ' +
|
|
108
|
+
'Install them with: npm install @bull-board/api @bull-board/fastify');
|
|
109
|
+
this.name = 'BullBoardNotInstalledError';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=bull-board.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bull-board.js","sourceRoot":"","sources":["../../src/monitoring/bull-board.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AA2BH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAoB,EACpB,OAAyB;IAEzB,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,eAAe,EAAE,IAAI,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE3E,8DAA8D;IAC9D,IAAI,eAAoB,CAAC;IACzB,8DAA8D;IAC9D,IAAI,aAAkB,CAAC;IACvB,8DAA8D;IAC9D,IAAI,cAAmB,CAAC;IAExB,IAAI,CAAC;QACH,8DAA8D;QAC9D,uCAAuC;QACvC,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,eAAe,CAAC;QAC7D,cAAc,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,cAAc,CAAC;QAC/D,aAAa,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC,aAAa,CAA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AY,EAAE,EAAE;YACzB,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,KAAK,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC;YACrE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,WAAW,EAAE,CAAC,SAAiB,EAAE,EAAE;YACjC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD;QACE,KAAK,CACH,yCAAyC;YACzC,oEAAoE,CACrE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QueueProvider - Main provider for queue lifecycle management
|
|
3
|
+
*
|
|
4
|
+
* Implements OnProviderInit and OnProviderDestroy for Rikta lifecycle integration.
|
|
5
|
+
* Not @Injectable - use createQueueProvider() factory function.
|
|
6
|
+
*/
|
|
7
|
+
import type { OnProviderInit, OnProviderDestroy } from '@riktajs/core';
|
|
8
|
+
import { Queue } from 'bullmq';
|
|
9
|
+
import type { QueueProviderOptions, QueueConfig } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* QueueProvider manages the lifecycle of all queues and workers.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const provider = createQueueProvider({
|
|
16
|
+
* config: { redis: { host: 'localhost', port: 6379 } }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // In Rikta bootstrap:
|
|
20
|
+
* await app.register(provider);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class QueueProvider implements OnProviderInit, OnProviderDestroy {
|
|
24
|
+
private connectionManager;
|
|
25
|
+
private config;
|
|
26
|
+
private queues;
|
|
27
|
+
private workers;
|
|
28
|
+
private processorClasses;
|
|
29
|
+
private initialized;
|
|
30
|
+
private eventBus;
|
|
31
|
+
private options;
|
|
32
|
+
/**
|
|
33
|
+
* Configure the provider with options
|
|
34
|
+
*/
|
|
35
|
+
configure(options: QueueProviderOptions): this;
|
|
36
|
+
/**
|
|
37
|
+
* Register processor classes for auto-discovery
|
|
38
|
+
*/
|
|
39
|
+
registerProcessors(...processors: Function[]): this;
|
|
40
|
+
/**
|
|
41
|
+
* Set EventBus for event emission (optional)
|
|
42
|
+
*/
|
|
43
|
+
setEventBus(eventBus: unknown): this;
|
|
44
|
+
/**
|
|
45
|
+
* Initialize all queues and workers (called by Rikta lifecycle)
|
|
46
|
+
*/
|
|
47
|
+
onProviderInit(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Gracefully shutdown all workers and close connections
|
|
50
|
+
*/
|
|
51
|
+
onProviderDestroy(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get a queue by name
|
|
54
|
+
*/
|
|
55
|
+
getQueue(name: string): Queue | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Get all registered queues
|
|
58
|
+
*/
|
|
59
|
+
getAllQueues(): Queue[];
|
|
60
|
+
/**
|
|
61
|
+
* Check if the provider is initialized
|
|
62
|
+
*/
|
|
63
|
+
isInitialized(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Get configuration
|
|
66
|
+
*/
|
|
67
|
+
getConfig(): QueueConfig;
|
|
68
|
+
private testConnection;
|
|
69
|
+
private discoverAndRegisterProcessors;
|
|
70
|
+
private registerProcessor;
|
|
71
|
+
private createQueue;
|
|
72
|
+
private attachWorkerEvents;
|
|
73
|
+
private handleEvent;
|
|
74
|
+
private registerInContainer;
|
|
75
|
+
private delay;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Factory function to create a QueueProvider
|
|
79
|
+
*/
|
|
80
|
+
export declare function createQueueProvider(options?: QueueProviderOptions): QueueProvider;
|
|
81
|
+
/**
|
|
82
|
+
* Error thrown when queue initialization fails
|
|
83
|
+
*/
|
|
84
|
+
export declare class QueueInitializationError extends Error {
|
|
85
|
+
readonly cause?: Error | undefined;
|
|
86
|
+
constructor(message: string, cause?: Error | undefined);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Error thrown when a duplicate queue is detected
|
|
90
|
+
*/
|
|
91
|
+
export declare class DuplicateQueueError extends Error {
|
|
92
|
+
constructor(queueName: string);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=queue.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.provider.d.ts","sourceRoot":"","sources":["../../src/providers/queue.provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,EAAuB,MAAM,QAAQ,CAAC;AAOpD,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EAGZ,MAAM,aAAa,CAAC;AAwBrB;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAc,YAAW,cAAc,EAAE,iBAAiB;IACrE,OAAO,CAAC,iBAAiB,CAAgC;IACzD,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAiB;IAEjC,OAAO,CAAC,OAAO,CAIb;IAEF;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAK9C;;OAEG;IACH,kBAAkB,CAAC,GAAG,UAAU,EAAE,QAAQ,EAAE,GAAG,IAAI;IAKnD;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAKpC;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IA2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