@pikku/queue-pg-boss 0.12.13 → 0.12.14
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PgBoss, Request as PgBossRequest } from 'pg-boss';
|
|
2
2
|
import type { QueueJob, QueueService } from '@pikku/core/queue';
|
|
3
|
-
import type
|
|
3
|
+
import { type JobOptions } from '@pikku/core/queue';
|
|
4
4
|
export declare const mapPikkuJobToPgBoss: (options?: JobOptions) => PgBossRequest['options'];
|
|
5
5
|
/**
|
|
6
6
|
* pg-boss/PostgreSQL queue service implementation
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { wrapJobTrace } from '@pikku/core/queue';
|
|
1
2
|
import { mapPgBossJobToQueueJob } from './utils.js';
|
|
2
3
|
export const mapPikkuJobToPgBoss = (options) => {
|
|
3
4
|
const pgBossOptions = {};
|
|
@@ -63,7 +64,7 @@ export class PgBossQueueService {
|
|
|
63
64
|
*/
|
|
64
65
|
async add(queueName, data, options) {
|
|
65
66
|
await this.pgBoss.createQueue(queueName);
|
|
66
|
-
const jobId = await this.pgBoss.send(queueName, data, mapPikkuJobToPgBoss(options));
|
|
67
|
+
const jobId = await this.pgBoss.send(queueName, wrapJobTrace(data, options?.traceparent, options?.pikkuUserId), mapPikkuJobToPgBoss(options));
|
|
67
68
|
if (!jobId) {
|
|
68
69
|
throw new Error('Failed to create job');
|
|
69
70
|
}
|
|
@@ -19,7 +19,7 @@ export declare class PgBossSchedulerService extends SchedulerService {
|
|
|
19
19
|
* Schedule a one-off delayed RPC call
|
|
20
20
|
* Uses pg-boss send() with startAfter for one-time execution
|
|
21
21
|
*/
|
|
22
|
-
scheduleRPC(delay: number | string, rpcName: string, data?: any, session?: CoreUserSession): Promise<string>;
|
|
22
|
+
scheduleRPC(delay: number | string, rpcName: string, data?: any, session?: CoreUserSession, traceparent?: string): Promise<string>;
|
|
23
23
|
/**
|
|
24
24
|
* Unschedule (cancel) a task by ID
|
|
25
25
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrapJobTrace, wrapJobTrace } from '@pikku/core/queue';
|
|
1
2
|
import { runScheduledTask } from '@pikku/core/scheduler';
|
|
2
3
|
import { SchedulerService } from '@pikku/core/services';
|
|
3
4
|
import { parseDurationString } from '@pikku/core/utils';
|
|
@@ -27,7 +28,7 @@ export class PgBossSchedulerService extends SchedulerService {
|
|
|
27
28
|
* Schedule a one-off delayed RPC call
|
|
28
29
|
* Uses pg-boss send() with startAfter for one-time execution
|
|
29
30
|
*/
|
|
30
|
-
async scheduleRPC(delay, rpcName, data, session) {
|
|
31
|
+
async scheduleRPC(delay, rpcName, data, session, traceparent) {
|
|
31
32
|
// Parse delay if it's a string
|
|
32
33
|
const delayMs = typeof delay === 'string' ? parseDurationString(delay) : delay;
|
|
33
34
|
const jobData = {
|
|
@@ -36,7 +37,7 @@ export class PgBossSchedulerService extends SchedulerService {
|
|
|
36
37
|
session,
|
|
37
38
|
};
|
|
38
39
|
// Use send() with startAfter for one-off delayed execution
|
|
39
|
-
const taskId = await this.pgBoss.send('pikku-mesh-rpc', jobData, {
|
|
40
|
+
const taskId = await this.pgBoss.send('pikku-mesh-rpc', wrapJobTrace(jobData, traceparent), {
|
|
40
41
|
startAfter: new Date(Date.now() + delayMs),
|
|
41
42
|
singletonKey: `${rpcName}-${Date.now()}`, // Ensure uniqueness
|
|
42
43
|
});
|
|
@@ -60,7 +61,7 @@ export class PgBossSchedulerService extends SchedulerService {
|
|
|
60
61
|
if (!job) {
|
|
61
62
|
return null;
|
|
62
63
|
}
|
|
63
|
-
const jobData = job.data;
|
|
64
|
+
const jobData = unwrapJobTrace(job.data).data;
|
|
64
65
|
return {
|
|
65
66
|
taskId: job.id,
|
|
66
67
|
rpcName: jobData.rpcName,
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrapJobTrace } from '@pikku/core/queue';
|
|
1
2
|
/**
|
|
2
3
|
* Map pg-boss job state to our queue job status
|
|
3
4
|
*/
|
|
@@ -22,10 +23,13 @@ const mapPgBossStateToStatus = (state) => {
|
|
|
22
23
|
* Map pg-boss job to QueueJob interface
|
|
23
24
|
*/
|
|
24
25
|
export const mapPgBossJobToQueueJob = (pgBossJob, pgBossInstance) => {
|
|
26
|
+
const { data, traceparent, pikkuUserId } = unwrapJobTrace(pgBossJob.data);
|
|
25
27
|
return {
|
|
26
28
|
queueName: pgBossJob.name,
|
|
27
29
|
id: pgBossJob.id || '',
|
|
28
|
-
data
|
|
30
|
+
data,
|
|
31
|
+
traceparent,
|
|
32
|
+
pikkuUserId,
|
|
29
33
|
status: async () => {
|
|
30
34
|
const jobWithState = await pgBossInstance.getJobById(pgBossJob.name, pgBossJob.id);
|
|
31
35
|
return mapPgBossStateToStatus(jobWithState?.state || 'created');
|
|
@@ -64,7 +68,7 @@ export const mapPgBossJobToQueueJob = (pgBossJob, pgBossInstance) => {
|
|
|
64
68
|
failedAt: pgBossJob.state === 'failed' && pgBossJob.completedOn
|
|
65
69
|
? new Date(pgBossJob.completedOn)
|
|
66
70
|
: undefined,
|
|
67
|
-
error:
|
|
71
|
+
error: data?.error,
|
|
68
72
|
};
|
|
69
73
|
},
|
|
70
74
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/queue-pg-boss",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.14",
|
|
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
|
"pg-boss": "^12.38.0"
|