mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
* error-handling-draft * feat: array based module loading (#379) Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> * Update utility.ts * Update sern.ts * describesemanticsbetter --------- Co-authored-by: Duro <davidwright13503@gmail.com>
22 lines
905 B
TypeScript
22 lines
905 B
TypeScript
import * as Files from '../core/module-loading'
|
|
import { UnpackedDependencies, Wrapper } from "../types/utility";
|
|
import type { ScheduledTask } from "../types/core-modules";
|
|
import { relative } from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
export const registerTasks = async (tasksDirs: string | string[], deps: UnpackedDependencies) => {
|
|
const taskManager = deps['@sern/scheduler']
|
|
|
|
const directories = Array.isArray(tasksDirs) ? tasksDirs : [tasksDirs];
|
|
|
|
for (const dir of directories) {
|
|
for await (const path of Files.readRecursive(dir)) {
|
|
let { module } = await Files.importModule<ScheduledTask>(path);
|
|
//module.name is assigned by Files.importModule<>
|
|
// the id created for the task is unique
|
|
const uuid = module.name+"/"+relative(dir,fileURLToPath(path))
|
|
taskManager.schedule(uuid, module, deps)
|
|
}
|
|
}
|
|
}
|