UNPKG

1.36 kBTypeScriptView Raw
1import { EventEmitter } from "events";
2
3/**
4 * Creates a new task to execute the given function when the cron expression ticks.
5 * @param cronExpression
6 * @param func
7 * @param options
8 */
9export function schedule(
10 cronExpression: string,
11 func: ((now: Date | "manual" | "init") => void) | string,
12 options?: ScheduleOptions,
13): ScheduledTask;
14
15/**
16 * To validate whether the expression is a cron expression or not
17 * @param cronExpression
18 */
19export function validate(cronExpression: string): boolean;
20
21/**
22 * Get the list of tasks created using the `schedule` function
23 */
24export function getTasks(): Map<string, ScheduledTask>;
25
26export interface ScheduledTask extends EventEmitter {
27 now: (now?: Date) => void;
28 start: () => void;
29 stop: () => void;
30}
31
32export interface ScheduleOptions {
33 /**
34 * A boolean to set if the created task is scheduled.
35 *
36 * Defaults to `true`
37 */
38 scheduled?: boolean | undefined;
39 /**
40 * The timezone that is used for job scheduling
41 */
42 timezone?: string;
43 /**
44 * Specifies whether to recover missed executions instead of skipping them.
45 *
46 * Defaults to `false`
47 */
48 recoverMissedExecutions?: boolean;
49 /**
50 * The schedule name
51 */
52 name?: string;
53 /**
54 * Execute task immediately after creation
55 */
56 runOnInit?: boolean;
57}