mirror of
https://github.com/sern-handler/handler
synced 2026-06-22 15:52:16 +00:00
cron works now, poc
This commit is contained in:
@@ -71,7 +71,7 @@ async function composeRoot(
|
||||
__add_container('@sern/logger', new __Services.DefaultLogging());
|
||||
}
|
||||
__add_container('@sern/errors', new __Services.DefaultErrorHandling());
|
||||
__add_container('@sern/cron', {})
|
||||
__add_container('@sern/cron', new __Services.Cron())
|
||||
__add_container('@sern/modules', new Map())
|
||||
__add_container('@sern/emitter', new EventEmitter())
|
||||
//Build the container based on the callback provided by the user
|
||||
@@ -98,7 +98,7 @@ export async function makeDependencies (conf: ValidDependencyConfig) {
|
||||
__add_container('@sern/logger', new __Services.DefaultLogging);
|
||||
}
|
||||
__add_container('@sern/errors', new __Services.DefaultErrorHandling());
|
||||
__add_container('@sern/cron', {})
|
||||
__add_container('@sern/cron', new __Services.Cron())
|
||||
__add_container('@sern/modules', new Map())
|
||||
__add_container('@sern/emitter', new EventEmitter())
|
||||
await useContainerRaw().ready();
|
||||
|
||||
@@ -52,14 +52,17 @@ export class Cron extends EventEmitter {
|
||||
modules: Map<string, CronEventCommand> = new Map();
|
||||
private sanityCheck(eventName: string | symbol) : asserts eventName is string {
|
||||
if(typeof eventName === 'symbol') throw Error("Cron cannot add symbol based listener")
|
||||
if(!cron.validate(eventName)) {
|
||||
throw Error("Invalid cron expression while adding")
|
||||
}
|
||||
|
||||
}
|
||||
addCronModule(module: Module) {
|
||||
if(module.type !== EventType.Cron) {
|
||||
throw Error("Can only add cron modules");
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
if(!cron.validate(module.pattern)) {
|
||||
throw Error("Invalid cron expression while adding")
|
||||
}
|
||||
this.modules.set(module.name!, module as CronEventCommand);
|
||||
}
|
||||
addListener(eventName: string | symbol, listener: AnyFunction): this {
|
||||
|
||||
Reference in New Issue
Block a user