import {Directive, OptionDefinition} from '../../Directive' import {Inject, Injectable} from '../../../di' import {Queue} from '../../../support/bus' import {Queueables} from '../../../service/Queueables' @Injectable() export class WorkDirective extends Directive { @Inject() protected readonly queue!: Queue @Inject() protected readonly queueables!: Queueables getDescription(): string { return 'pop a single item from the queue and execute it' } getKeywords(): string | string[] { return 'queue-work' } getOptions(): OptionDefinition[] { return [] } async handle(): Promise { try { const queueable = await this.queue.pop() if ( !queueable ) { this.info('There are no items in the queue.') return } this.info(`Fetched 1 item from the queue`) await queueable.execute() this.success('Executed 1 item from the queue') } catch (e: unknown) { this.error('Failed to execute queueable:') this.error(e) process.exitCode = 1 } } }