@boopkit/cap-background-jobs 0.2.1 → 0.2.2
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/package.json +1 -1
- package/scaffold/src/scheduler.ts +30 -0
package/package.json
CHANGED
|
@@ -69,11 +69,15 @@ function printUsage(): void {
|
|
|
69
69
|
|
|
70
70
|
Commands:
|
|
71
71
|
run-jobs Publish trigger messages to matching job queues
|
|
72
|
+
publish Publish a single message to a queue and exit
|
|
72
73
|
list List all registered jobs
|
|
73
74
|
|
|
74
75
|
Options:
|
|
75
76
|
--interval <tag> Filter jobs by interval tag (e.g. 10-minutes, 60-minutes)
|
|
76
77
|
--job <name> Filter jobs by name
|
|
78
|
+
--queue <name> Target queue for publish command
|
|
79
|
+
--task <name> Task name for publish payload (default: "cli")
|
|
80
|
+
--data <json> JSON string of extra data for publish payload
|
|
77
81
|
`);
|
|
78
82
|
}
|
|
79
83
|
|
|
@@ -104,6 +108,32 @@ async function main(args: string[], opts: Record<string, unknown>): Promise<void
|
|
|
104
108
|
break;
|
|
105
109
|
}
|
|
106
110
|
|
|
111
|
+
case 'publish': {
|
|
112
|
+
const queue = opts.queue as string | undefined;
|
|
113
|
+
if (!queue) {
|
|
114
|
+
console.error('[scheduler] --queue is required for publish command');
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
const task = (opts.task as string) ?? 'cli';
|
|
118
|
+
let data: Record<string, unknown> = {};
|
|
119
|
+
if (opts.data) {
|
|
120
|
+
try {
|
|
121
|
+
data = JSON.parse(opts.data as string);
|
|
122
|
+
} catch {
|
|
123
|
+
console.error('[scheduler] --data must be valid JSON');
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const ok = await MessageQueueService.publish(queue, { task, data });
|
|
128
|
+
if (ok) {
|
|
129
|
+
console.log(`[scheduler] published to "${queue}": ${task}`);
|
|
130
|
+
} else {
|
|
131
|
+
console.error(`[scheduler] failed to publish to "${queue}"`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
|
|
107
137
|
default:
|
|
108
138
|
console.error(`[scheduler] unknown command: ${command}`);
|
|
109
139
|
printUsage();
|