You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
2 years ago
|
import {Directive, OptionDefinition} from '../../Directive'
|
||
|
import {Inject, Injectable} from '../../../di'
|
||
|
import {Queue} from '../../../support/bus'
|
||
|
|
||
|
@Injectable()
|
||
|
export class WorkDirective extends Directive {
|
||
|
@Inject()
|
||
|
protected readonly queue!: Queue
|
||
|
|
||
|
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<void> {
|
||
|
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
|
||
|
}
|
||
|
}
|
||
|
}
|