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 | async send(name, data, opts = {}) { | 83 | async send(name, data, opts = {}) { | ||
| 84 | await ensure(name); | 84 | await ensure(name); | ||
| 85 | − return boss.send(name, data, { | 85 | + // pg-boss asserts on explicitly-undefined option keys (e.g. "priority must be an integer"): only pass defined ones. | ||
| 86 | − singletonKey: opts.singletonKey, | 86 | + const sendOpts: Record<string, unknown> = {}; | ||
| 87 | − singletonSeconds: opts.singletonSeconds, | 87 | + if (opts.singletonKey !== undefined) sendOpts.singletonKey = opts.singletonKey; | ||
| 88 | − priority: opts.priority, | 88 | + if (opts.singletonSeconds !== undefined) sendOpts.singletonSeconds = opts.singletonSeconds; | ||
| 89 | − startAfter: opts.startAfterSeconds, | 89 | + if (opts.priority !== undefined) sendOpts.priority = Math.trunc(opts.priority); | ||
| 90 | − retryLimit: opts.retryLimit, | 90 | + if (opts.startAfterSeconds !== undefined) sendOpts.startAfter = opts.startAfterSeconds; | ||
| 91 | − expireInSeconds: opts.expireInSeconds, | 91 | + if (opts.retryLimit !== undefined) sendOpts.retryLimit = opts.retryLimit; | ||
| 92 | − }); | 92 | + if (opts.expireInSeconds !== undefined) sendOpts.expireInSeconds = opts.expireInSeconds; | ||
| 93 | + return boss.send(name, data, sendOpts); | ||||
| 93 | }, | 94 | }, | ||
| 94 | async schedule(name, cron, data = {}, opts = {}) { | 95 | async schedule(name, cron, data = {}, opts = {}) { | ||
| 95 | await ensure(name); | 96 | await ensure(name); | ||
| 96 | 97 | ||||