Skip to content

Commit

Permalink
fix(jobs): merge job options to prevent 'undefined' values in place o…
Browse files Browse the repository at this point in the history
…f 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.
  • Loading branch information
Josh-Walker-GM committed Oct 8, 2024
1 parent b24d9b1 commit 7b9be2b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/jobs/src/core/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ export class Worker {
lastCheckTime: Date

constructor(options: WorkerOptions) {
this.options = { ...DEFAULT_OPTIONS, ...options }
// Note: if we did a simple spread like { ...DEFAULT_OPTIONS, ...options } then any undefined values in `options`
// would override the defaults. We want to keep the defaults if the value is `undefined` so we have to do this
const nonUndefinedOptions = Object.fromEntries(
Object.entries(options ?? {}).filter(([_, value]) => value !== undefined),
)
this.options = {
...DEFAULT_OPTIONS,
...nonUndefinedOptions,
adapter: options?.adapter,
processName: options?.processName,
queues: options?.queues,
}

if (!options?.adapter) {
throw new AdapterRequiredError()
Expand Down

0 comments on commit 7b9be2b

Please sign in to comment.