@pikku/queue-bullmq 0.12.10 → 0.12.12
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.
|
@@ -2,7 +2,7 @@ import type { ConnectionOptions, JobsOptions } from 'bullmq';
|
|
|
2
2
|
import type Bull from 'bullmq';
|
|
3
3
|
import { Queue, QueueEvents } from 'bullmq';
|
|
4
4
|
import type { QueueInspection, QueueJob, QueueJobRecord, QueueJobStatus, QueueService } from '@pikku/core/queue';
|
|
5
|
-
import type
|
|
5
|
+
import { type JobOptions } from '@pikku/core/queue';
|
|
6
6
|
export declare const mapPikkuJobToBull: (options?: JobOptions) => JobsOptions;
|
|
7
7
|
export declare const mapBullJobToRecord: (job: Bull.Job, status: QueueJobStatus) => QueueJobRecord;
|
|
8
8
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Queue, QueueEvents } from 'bullmq';
|
|
2
|
+
import { wrapJobTrace } from '@pikku/core/queue';
|
|
2
3
|
import { mapBullJobToQueueJob } from './utils.js';
|
|
3
4
|
export const mapPikkuJobToBull = (options) => {
|
|
4
5
|
const bullOptions = {};
|
|
@@ -68,7 +69,7 @@ export class BullQueueService {
|
|
|
68
69
|
if (this.queues.has(queueName)) {
|
|
69
70
|
return this.queues.get(queueName);
|
|
70
71
|
}
|
|
71
|
-
const queue = new Queue(queueName, config);
|
|
72
|
+
const queue = new Queue(queueName, config ?? { connection: this.redisConnectionOptions });
|
|
72
73
|
queue.on('error', (error) => {
|
|
73
74
|
console.error('Redis connection error:', error);
|
|
74
75
|
});
|
|
@@ -88,7 +89,7 @@ export class BullQueueService {
|
|
|
88
89
|
*/
|
|
89
90
|
async add(queueName, data, options) {
|
|
90
91
|
const queue = await this.createQueue(queueName);
|
|
91
|
-
const bullJob = await queue.add(queueName, data, mapPikkuJobToBull(options));
|
|
92
|
+
const bullJob = await queue.add(queueName, wrapJobTrace(data, options?.traceparent, options?.pikkuUserId), mapPikkuJobToBull(options));
|
|
92
93
|
if (!bullJob.id) {
|
|
93
94
|
throw new Error(`Failed to add job to queue '${queueName}'.`);
|
|
94
95
|
}
|
|
@@ -17,7 +17,7 @@ export declare class BullSchedulerService extends SchedulerService {
|
|
|
17
17
|
* Schedule a one-off delayed RPC call
|
|
18
18
|
* Uses BullMQ add() with delay option
|
|
19
19
|
*/
|
|
20
|
-
scheduleRPC(delay: number | string, rpcName: string, data?: any, session?: CoreUserSession): Promise<string>;
|
|
20
|
+
scheduleRPC(delay: number | string, rpcName: string, data?: any, session?: CoreUserSession, traceparent?: string): Promise<string>;
|
|
21
21
|
/**
|
|
22
22
|
* Unschedule (remove) a task by ID
|
|
23
23
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrapJobTrace, wrapJobTrace } from '@pikku/core/queue';
|
|
1
2
|
import { Queue, Worker } from 'bullmq';
|
|
2
3
|
import { runScheduledTask } from '@pikku/core/scheduler';
|
|
3
4
|
import { SchedulerService } from '@pikku/core/services';
|
|
@@ -14,7 +15,7 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
14
15
|
constructor(redisConnectionOptions) {
|
|
15
16
|
super();
|
|
16
17
|
this.redisConnectionOptions = redisConnectionOptions;
|
|
17
|
-
this.queue = new Queue('pikku-
|
|
18
|
+
this.queue = new Queue('pikku-mesh-rpc', {
|
|
18
19
|
connection: redisConnectionOptions,
|
|
19
20
|
});
|
|
20
21
|
this.recurringQueue = new Queue(RECURRING_QUEUE_NAME, {
|
|
@@ -31,7 +32,7 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
31
32
|
* Schedule a one-off delayed RPC call
|
|
32
33
|
* Uses BullMQ add() with delay option
|
|
33
34
|
*/
|
|
34
|
-
async scheduleRPC(delay, rpcName, data, session) {
|
|
35
|
+
async scheduleRPC(delay, rpcName, data, session, traceparent) {
|
|
35
36
|
// Parse delay if it's a string
|
|
36
37
|
const delayMs = typeof delay === 'string' ? parseDurationString(delay) : delay;
|
|
37
38
|
const jobData = {
|
|
@@ -40,7 +41,7 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
40
41
|
session,
|
|
41
42
|
};
|
|
42
43
|
// Use add() with delay for one-off delayed execution
|
|
43
|
-
const job = await this.queue.add('pikku-
|
|
44
|
+
const job = await this.queue.add('pikku-mesh-rpc', wrapJobTrace(jobData, traceparent), {
|
|
44
45
|
delay: delayMs, // delay in milliseconds
|
|
45
46
|
jobId: `${rpcName}-${Date.now()}`, // Ensure uniqueness
|
|
46
47
|
});
|
|
@@ -68,7 +69,7 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
68
69
|
if (!job) {
|
|
69
70
|
return null;
|
|
70
71
|
}
|
|
71
|
-
const jobData = job.data;
|
|
72
|
+
const jobData = unwrapJobTrace(job.data).data;
|
|
72
73
|
const state = await job.getState();
|
|
73
74
|
// Calculate scheduled time from delay or processedOn
|
|
74
75
|
const scheduledFor = job.delay
|
|
@@ -89,7 +90,7 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
89
90
|
async getAllTasks() {
|
|
90
91
|
const jobs = await this.queue.getJobs(['delayed', 'waiting']);
|
|
91
92
|
return jobs.map((job) => {
|
|
92
|
-
const jobData = job.data;
|
|
93
|
+
const jobData = unwrapJobTrace(job.data).data;
|
|
93
94
|
const scheduledFor = job.delay
|
|
94
95
|
? new Date(job.timestamp + job.delay)
|
|
95
96
|
: new Date(job.timestamp);
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrapJobTrace } from '@pikku/core/queue';
|
|
1
2
|
import { QueueEvents } from 'bullmq';
|
|
2
3
|
/**
|
|
3
4
|
* Map Bull job state to our queue job status
|
|
@@ -22,10 +23,13 @@ const mapBullStateToStatus = (state) => {
|
|
|
22
23
|
* Map Bull job to QueueJob interface
|
|
23
24
|
*/
|
|
24
25
|
export const mapBullJobToQueueJob = async (bullJob, redisConnection, queueEventsMap) => {
|
|
26
|
+
const { data, traceparent, pikkuUserId } = unwrapJobTrace(bullJob.data);
|
|
25
27
|
return {
|
|
26
28
|
queueName: bullJob.name,
|
|
27
29
|
id: bullJob.id || '',
|
|
28
|
-
data
|
|
30
|
+
data,
|
|
31
|
+
traceparent,
|
|
32
|
+
pikkuUserId,
|
|
29
33
|
result: bullJob.returnvalue,
|
|
30
34
|
status: async () => mapBullStateToStatus(await bullJob.getState()),
|
|
31
35
|
waitForCompletion: async (ttl) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/queue-bullmq",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/pikkujs/pikku.git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@pikku/core": "^0.12.
|
|
25
|
+
"@pikku/core": "^0.12.151"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"bullmq": "^6.3.16",
|