Add support for jobs & queueables, migrations
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing

- Create migration directives & migrators
- Modify Cache classes to support array manipulation
- Create Redis unit and RedisCache implementation
- Create Queueable base class and Queue class that uses Cache backend
This commit is contained in:
2021-08-23 23:51:53 -05:00
parent 26e0444e40
commit 074a3187eb
28 changed files with 962 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
import {Canonical} from './Canonical'
import {Singleton} from '../di'
import {Maybe} from '../util'
/**
* Error throw when a duplicate canonical key is registered.
@@ -46,6 +47,17 @@ export class Canon {
return this.resources[key] as Canonical<T>
}
/**
* Get a canonical item from a fully-qualified canonical name.
* This is just a quality-of-life wrapper around `this.resource(...).get(...)`.
* @param key
*/
getFromFullyQualified(key: string): Maybe<any> {
const [namespace, ...parts] = key.split('::')
const unqualified = parts.join('::')
return this.resource(namespace).get(unqualified)
}
/**
* Register a canonical resource.
* @param {Canonical} unit

View File

@@ -7,6 +7,7 @@ import {Logging} from './Logging'
import {Inject} from '../di'
import * as nodePath from 'path'
import {Unit} from '../lifecycle/Unit'
import {isCanonicalReceiver} from '../support/CanonicalReceiver'
/**
* Interface describing a definition of a single canonical item loaded from the app.
@@ -228,7 +229,16 @@ export abstract class Canonical<T> extends Unit {
const definition = await this.buildCanonicalDefinition(entry)
this.logging.verbose(`Registering canonical ${this.canonicalItem} "${definition.canonicalName}" from ${entry}`)
this.loadedItems[definition.canonicalName] = await this.initCanonicalItem(definition)
const resolvedItem = await this.initCanonicalItem(definition)
if ( isCanonicalReceiver(resolvedItem) ) {
resolvedItem.setCanonicalResolver(
`${this.canonicalItems}::${definition.canonicalName}`,
definition.canonicalName,
)
}
this.loadedItems[definition.canonicalName] = resolvedItem
}
this.canon.registerCanonical(this)

25
src/service/Queueables.ts Normal file
View File

@@ -0,0 +1,25 @@
import {CanonicalStatic} from './CanonicalStatic'
import {Singleton, Instantiable, StaticClass} from '../di'
import {CanonicalDefinition} from './Canonical'
import {Queueable} from '../support/queue/Queue'
/**
* A canonical unit that resolves Queueable classes from `app/queueables`.
*/
@Singleton()
export class Queueables extends CanonicalStatic<Queueable, Instantiable<Queueable>> {
protected appPath = ['queueables']
protected canonicalItem = 'job'
protected suffix = '.job.js'
public async initCanonicalItem(definition: CanonicalDefinition): Promise<StaticClass<Queueable, Instantiable<Queueable>>> {
const item = await super.initCanonicalItem(definition)
if ( !(item.prototype instanceof Queueable) ) {
throw new TypeError(`Invalid middleware definition: ${definition.originalName}. Controllers must extend from @extollo/lib.Queueable.`)
}
return item
}
}