import { Task, ScheduleConfig } from './helpers/task-scheduler'; import { IInputProvider, ILogger } from '../../types'; import { ICoreSchedulerInput } from '../types/scheduler-types'; export interface ICoreInputSchedulerProviderOptions { inputContextCallback?: (req: ICoreSchedulerInput) => void; } export default class CoreInputSchedulerProvider implements IInputProvider { private alreadyRegistered; private logger?; private scheduler; private applyInputCb; private options; /** * constructor * * This function sets class level variables. * * @param schedulerConfig - Schedule configuration for the task scheduler * @param logger - a logger instance to use for logging. * @param options **/ constructor(schedulerConfig: ScheduleConfig, logger: ILogger | undefined, options: ICoreInputSchedulerProviderOptions); /** * registerHandler * This is called by the rules engine when it starts. This function starts the task scheduler * * Do this by... * 1. Set the rules engine apply function for use later * 2. If we are not already setup then start the scheduler * * @param applyInputCb - a handler that will be called when there is input. It should be passed input and context. * @returns Promise **/ registerInput(applyInputCb: (input: any, context: any) => Promise): Promise; /** * schedulerHandler * Handle the scheduler interval * * does this by * 1. Build input facts * 2. Optionaly call inputContextCallback if it is defined to build a context * 3. Pass input facts and context to the rules engine */ schedulerHandler(task: Task): Promise; unregisterInput(): Promise; }