Package version
@adonisjs/queue@0.6.0
Describe the bug
Summary
@adonisjs/queue appears to eagerly initialize job autodiscovery during unrelated Ace commands like node ace migration:run.
In this reproduction repo:
- queue autodiscovery is enabled via
locations in config/queue.ts
app/jobs/check_user_job.ts imports User
app/models/user.ts extends UserSchema from #database/schema
After rolling back all migrations, database/schema.ts no longer exports UserSchema. Running node ace migration:run then causes queue boot to import the job before the migration regenerates the schema classes.
This does not stop the migration from finishing, but it does emit a boot-time error for an unrelated job import during command startup.
Steps To Reproduce
node ace migration:rollback --batch=0
node ace migration:run
What Seems To Happen
The boot chain seems to be:
- Run an unrelated Ace command such as
node ace migration:run
- App boots in console mode
- Queue initializes and scans
locations
- Job files are imported during startup
- A job import pulls in a model
- The model imports a generated class from
#database/schema
- If
database/schema.ts is temporarily stale or empty after rollback, startup logs the import failure before the migration regenerates the schema classes
Actual Behavior
During migration:run, queue autodiscovery imports the job too early and logs:
Failed to load job from app/jobs/check_user_job.ts: .../app/models/user.ts:1
import { UserSchema } from '#database/schema'
SyntaxError: The requested module '#database/schema' does not provide an export named 'UserSchema'
After that, the migrations still complete and database/schema.ts is regenerated successfully.
So the problem is not that the migration fails. The problem is that queue boot imports autodiscovered jobs during startup for an unrelated console command.
Expected Behavior
Unrelated console commands like migration:run should not require every autodiscovered job to be importable before the command finishes its own work.
I do not think the fix is to disable queue support in console entirely, since queue console commands still need that environment, for example:
node ace queue:work
node ace queue:scheduler:list
node ace queue:scheduler:clear
node ace queue:scheduler:remove
The issue seems more like queue initialization and job discovery happening for all console commands instead of only queue-related ones or actual queue usage.
Notes
- This reproduction repo uses SQLite, but I am having it also on my app with Postgres.
- If
locations is commented out in config/queue.ts, the error does not happen.
- This suggests the issue is tied to eager queue job autodiscovery during unrelated console boot, rather than migrations themselves.
Versions
@adonisjs/core: ^7.3.1
@adonisjs/lucid: ^22.4.2
@adonisjs/queue: ^0.6.0
better-sqlite3: ^12.9.0
Reproduction repo
https://github.com/diego-sepulveda-lavin/adonisjs_queue_bug_reproduction
Package version
@adonisjs/queue@0.6.0
Describe the bug
Summary
@adonisjs/queueappears to eagerly initialize job autodiscovery during unrelated Ace commands likenode ace migration:run.In this reproduction repo:
locationsinconfig/queue.tsapp/jobs/check_user_job.tsimportsUserapp/models/user.tsextendsUserSchemafrom#database/schemaAfter rolling back all migrations,
database/schema.tsno longer exportsUserSchema. Runningnode ace migration:runthen causes queue boot to import the job before the migration regenerates the schema classes.This does not stop the migration from finishing, but it does emit a boot-time error for an unrelated job import during command startup.
Steps To Reproduce
What Seems To Happen
The boot chain seems to be:
node ace migration:runlocations#database/schemadatabase/schema.tsis temporarily stale or empty after rollback, startup logs the import failure before the migration regenerates the schema classesActual Behavior
During
migration:run, queue autodiscovery imports the job too early and logs:After that, the migrations still complete and
database/schema.tsis regenerated successfully.So the problem is not that the migration fails. The problem is that queue boot imports autodiscovered jobs during startup for an unrelated console command.
Expected Behavior
Unrelated console commands like
migration:runshould not require every autodiscovered job to be importable before the command finishes its own work.I do not think the fix is to disable queue support in console entirely, since queue console commands still need that environment, for example:
node ace queue:worknode ace queue:scheduler:listnode ace queue:scheduler:clearnode ace queue:scheduler:removeThe issue seems more like queue initialization and job discovery happening for all console commands instead of only queue-related ones or actual queue usage.
Notes
locationsis commented out inconfig/queue.ts, the error does not happen.Versions
@adonisjs/core:^7.3.1@adonisjs/lucid:^22.4.2@adonisjs/queue:^0.6.0better-sqlite3:^12.9.0Reproduction repo
https://github.com/diego-sepulveda-lavin/adonisjs_queue_bug_reproduction