Repository navigation
Open
Labels
status: reviewThe status of the hub task
Description
Goal
Locator.registerFromGlob() imports each job file. When a file throws on import or has a syntax error, it logs the error at the error level, skips the file, and goes on (src/locator.ts). The caller cannot know that a file failed. queue:work of @adonisjs/queue must exit with code 1 when a job file fails to load (T-092). It needs an option that throws in place of the log.
- Expected: with
strict: true,registerFromGlob()andQueueManager.loadJobs()throwE_JOB_LOAD_FAILEDfor the first job file that fails to import. - Actual: they log the error and return the number of the other jobs.
- Steps: a job file that contains
throw new Error('boom'). CallLocator.registerFromGlob([file]).
Acceptance criteria
-
RegisterFromGlobOptionshasstrict?: boolean. Withstrict: true, a file that fails to import throwsE_JOB_LOAD_FAILEDat once, with the messageCannot load job from "<file>"and the import error incause. Nothing is logged for that file. -
QueueManager.loadJobs(locations?, options?)accepts{ strict?: boolean }as its second argument and gives it toregisterFromGlob().locationsstays optional, andundefinedgives the configured locations. - With no
strictoption, orstrict: false, the behaviour is the same as in 0.10.0: the error is logged at theerrorlevel, the file is skipped, and the other jobs are registered. -
E_JOB_LOAD_FAILEDis exported with the other errors of the package. - Tests prove
strict: truefor a file that throws on import and for a file with a syntax error, throughregisterFromGlob()and throughloadJobs(). They also prove that a file with no default export does not throw withstrict: true. -
README.mddocuments thestrictoption.
Implementation decisions
src/exceptions.ts:E_JOB_LOAD_FAILED = createError<[file: string]>('Cannot load job from "%s"', 'E_JOB_LOAD_FAILED'), like the other errors of the file. Reason: the import error of a file that throws does not name the file, so the new error gives it, andcausekeeps the original error.src/locator.ts: in thecatchof the import, whenoptions.strictis true, thrownew E_JOB_LOAD_FAILED([file], { cause: error }). Otherwise keep the log and thecontinue.src/queue_manager.ts:loadJobs(locations = this.#locations, options: { strict?: boolean } = {})passesstrictwithhotReloadandlogger.strictapplies only to a file that fails to import. A file with no default export, or a default export that is not a function, is still skipped with no error. Reason: the option is about a broken file, and the skip of other files is a separate behaviour.- Tests:
tests/locator.spec.tsandtests/queue_manager.spec.ts, with thefsfixture thatqueue_manager.spec.tsalready uses forbroken_job.js.
Out of scope
- A change to
QueueManager.init()or itsautoLoadJobs.init()keeps the log and the skip. - A change to the hot reload of a job before it runs.
- The change of
@adonisjs/queuethat uses the option (T-092).
Hub task T-131. Edit the task in the hub, not this issue.
Metadata
Metadata
Assignees
Labels
status: reviewThe status of the hub task
Activity