Skip to content

T-131: A strict option that throws on a job file that fails to load - #38

Open
thetutlage wants to merge 1 commit into
mainfrom
task/T-131
Open

thetutlage wants to merge 1 commit into
mainfrom
task/T-131

Conversation

@thetutlage

Copy link
Copy Markdown
Contributor

Fixes #37

Locator.registerFromGlob() logs a job file that fails to import and skips it, so the caller cannot know that the file failed. queue:work of @adonisjs/queue must exit with code 1 when a job file fails to load (adonisjs/queue#13). This adds a strict option that throws in place of the log.

await Locator.registerFromGlob(patterns, { strict: true })
await QueueManager.loadJobs(undefined, { strict: true })
// E_JOB_LOAD_FAILED: Cannot load job from "<file>", with the import error in `cause`

With no strict option, the behaviour is the same as in 0.10.0.

Deployment requirements

  • A minor release of @boringnode/queue: 0.11.0.

Acceptance criteria

  • RegisterFromGlobOptions.strict throws E_JOB_LOAD_FAILED at once, with the file in the message and the import error in cause, and logs nothing. Test: strict throws E_JOB_LOAD_FAILED for a file that throws on import in tests/locator.spec.ts.
  • QueueManager.loadJobs(locations?, { strict }) gives the option to registerFromGlob(), and undefined gives the configured locations. Tests: loadJobs with strict throws E_JOB_LOAD_FAILED for the configured locations and ... for explicit locations in tests/queue_manager.spec.ts.
  • With no strict, the file is logged at the error level and skipped, and the other jobs are registered. Tests: should log and skip a file that fails to load, and register the other jobs in tests/locator.spec.ts, and the existing should log a job file that fails to load through the logger.
  • E_JOB_LOAD_FAILED is exported with errors. File: src/exceptions.ts, exported by export * as errors of index.ts.
  • A file that throws, a file with a syntax error, and a file with no default export (no throw). Tests in tests/locator.spec.ts and tests/queue_manager.spec.ts.
  • README.md documents the option in the new section "Loading Jobs".

Checks

  • yarn lint, yarn format and yarn typecheck pass.
  • yarn test: 1755 passed, 1 failed. The failure is Schedule dates migration | Knex (postgres) / reads dates whatever the DateStyle and TimeZone of the session. It fails the same way on main (1749 passed, 1 failed), so it is not related to this change.

Context changes

None.

Discovered work

  • Schedule dates migration | Knex (postgres) / reads dates whatever the DateStyle and TimeZone of the session fails on main against postgres:alpine: it gets 1900-01-01T00:00:10.000Z where it expects 1900-01-01T00:00:00.000Z.

With strict: true, Locator.registerFromGlob() and QueueManager.loadJobs()
throw E_JOB_LOAD_FAILED for the first job file that fails to import, with
the import error as its cause. Without it, the file is logged and skipped,
as before. A worker process can use it to refuse to start with a broken
job file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A strict option that throws on a job file that fails to load

1 participant