See the best posts from any Bluesky account
1import QueueWorkBase from '@adonisjs/queue/commands/queue_work'
2
3/**
4 * Local shadow of @adonisjs/queue's queue:work command.
5 *
6 * Upstream declares staysAlive: true but never calls app.terminate() after
7 * the worker drains on SIGINT, so provider-held handles (Lucid pool, logger,
8 * etc.) keep the event loop alive and the process hangs until a second Ctrl-C
9 * forces Node's default-action exit. We wait for super.run() to finish
10 * (boringnode's shutdown handler has already drained the pool by then), then
11 * terminate the app and exit explicitly.
12 */
13export default class QueueWork extends QueueWorkBase {
14 async run() {
15 try {
16 await super.run()
17 } catch (error) {
18 this.logger.error(error instanceof Error ? error.message : String(error))
19 this.exitCode = 1
20 }
21
22 try {
23 await this.app.terminate()
24 } catch {
25 /* ignore */
26 }
27 process.exit(this.exitCode ?? 0)
28 }
29}