Skip to content

Commit 7b9be2b

Browse files
fix(jobs): merge job options to prevent 'undefined' values in place of defaults (#11666)
The E2E tests were failing. This highlighted that we were not overriding `undefined` with the expected default values. This update changes the merging to be a little more gross but works.
1 parent b24d9b1 commit 7b9be2b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/jobs/src/core/Worker.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ export class Worker {
7979
lastCheckTime: Date
8080

8181
constructor(options: WorkerOptions) {
82-
this.options = { ...DEFAULT_OPTIONS, ...options }
82+
// Note: if we did a simple spread like { ...DEFAULT_OPTIONS, ...options } then any undefined values in `options`
83+
// would override the defaults. We want to keep the defaults if the value is `undefined` so we have to do this
84+
const nonUndefinedOptions = Object.fromEntries(
85+
Object.entries(options ?? {}).filter(([_, value]) => value !== undefined),
86+
)
87+
this.options = {
88+
...DEFAULT_OPTIONS,
89+
...nonUndefinedOptions,
90+
adapter: options?.adapter,
91+
processName: options?.processName,
92+
queues: options?.queues,
93+
}
8394

8495
if (!options?.adapter) {
8596
throw new AdapterRequiredError()

0 commit comments

Comments
 (0)