Refactor event bus and queue system; detect cycles in DI realization and make
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-01-26 19:37:54 -06:00
parent 506fb55c74
commit 6d1cf18680
69 changed files with 1673 additions and 720 deletions

View File

@@ -13,7 +13,7 @@ export const CLIDirective = (): ClassDecorator => {
if ( isInstantiableOf(target, Directive) ) {
logIfDebugging('extollo.cli.decorators', 'Registering CLIDirective blueprint:', target)
ContainerBlueprint.getContainerBlueprint()
.onResolve<CommandLine>(CommandLine, cli => {
.onResolve<CommandLine>(CommandLine, (cli: CommandLine) => {
cli.registerDirective(target as Instantiable<Directive>)
})
} else {

View File

@@ -0,0 +1,39 @@
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
}
}
}

View File

@@ -9,6 +9,7 @@ import {TemplateDirective} from '../directive/TemplateDirective'
import {RunDirective} from '../directive/RunDirective'
import {RoutesDirective} from '../directive/RoutesDirective'
import {RouteDirective} from '../directive/RouteDirective'
import {WorkDirective} from '../directive/queue/WorkDirective'
/**
* Unit that takes the place of the final unit in the application that handles
@@ -46,6 +47,7 @@ export class CommandLineApplication extends Unit {
this.cli.registerDirective(RunDirective)
this.cli.registerDirective(RoutesDirective)
this.cli.registerDirective(RouteDirective)
this.cli.registerDirective(WorkDirective)
const argv = process.argv.slice(2)
const match = this.cli.getDirectives()