workers: only pass defined pg-boss send options (fixes normalize enqueue)
1 changed file +9 −8
modified
workers/lib/queue.ts
+9 −8
@@ -82,14 +82,15 @@ export function createQueue(): Queue { | ||
| 82 | 82 | }, |
| 83 | 83 | async send(name, data, opts = {}) { |
| 84 | 84 | await ensure(name); |
| 85 | − return boss.send(name, data, { | |
| 86 | − singletonKey: opts.singletonKey, | |
| 87 | − singletonSeconds: opts.singletonSeconds, | |
| 88 | − priority: opts.priority, | |
| 89 | − startAfter: opts.startAfterSeconds, | |
| 90 | − retryLimit: opts.retryLimit, | |
| 91 | − expireInSeconds: opts.expireInSeconds, | |
| 92 | − }); | |
| 85 | + // pg-boss asserts on explicitly-undefined option keys (e.g. "priority must be an integer"): only pass defined ones. | |
| 86 | + const sendOpts: Record<string, unknown> = {}; | |
| 87 | + if (opts.singletonKey !== undefined) sendOpts.singletonKey = opts.singletonKey; | |
| 88 | + if (opts.singletonSeconds !== undefined) sendOpts.singletonSeconds = opts.singletonSeconds; | |
| 89 | + if (opts.priority !== undefined) sendOpts.priority = Math.trunc(opts.priority); | |
| 90 | + if (opts.startAfterSeconds !== undefined) sendOpts.startAfter = opts.startAfterSeconds; | |
| 91 | + if (opts.retryLimit !== undefined) sendOpts.retryLimit = opts.retryLimit; | |
| 92 | + if (opts.expireInSeconds !== undefined) sendOpts.expireInSeconds = opts.expireInSeconds; | |
| 93 | + return boss.send(name, data, sendOpts); | |
| 93 | 94 | }, |
| 94 | 95 | async schedule(name, cron, data = {}, opts = {}) { |
| 95 | 96 | await ensure(name); |
| 96 | 97 | |