import DatabaseHandler, { DatabaseHandlerOptions } from './DatabaseHandler'; import Deffered from './Deffered'; import type GuaranteedTask from './GuaranteedTask'; import TaskChain from './TaskChain'; export declare type TaskRunnerOptions = { /** an array containing all classes that this runner gonna use */ Tasks: Array; /** possible dependency that is needed during a task */ dependency?: unknown; /** an array of functions that returns truthy or falsey values. * functions can be async or return promise. * Note that this is the global run conditions for all tasks */ runConditions?: Array<(() => Promise) | (() => boolean)>; /** rate of running checks in milliseconds. default 10 sec. */ conditionCheckRate?: number; /** delay in milliseconds to restart the task when it fails. default 10 sec. */ taskFailureDelay?: number; dbOptions?: DatabaseHandlerOptions; /** Never use this option. special option for debugging and testing. */ debug?: { /** It limits how many tasks can run per start. quota resets per stop. */ runLimit?: number; }; }; export default class TaskRunner { Tasks: Array; dependency: unknown; taskFailureDelay: number; runningTasks: Map>; private taskImmediates; private taskTimeouts; running: boolean; stopping: boolean; startDeffer: Deffered; stopDeffer: Deffered; private conditionRunner; db: DatabaseHandler; constructor(options: TaskRunnerOptions); /** * the last planned task gets inserted first, * the id and its name gets inserted with the task before it, * and so on * * till the first plan which is the top parent task gets inserted with has_parent as null */ execute(taskChain: TaskChain | typeof GuaranteedTask, args?: unknown): Promise; /** * Runs the defined task */ private run; private _runTaskId; /** * Stops executing tasks. * Wait for all current running tasks to finish. */ stop(): Promise; private _stop; private _start; start(): Promise; }