1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | import { EventEmitter } from 'events';
|
12 |
|
13 |
|
14 | export type JobCallback = (fireDate: Date) => void | Promise<any>;
|
15 |
|
16 |
|
17 | export class Job extends EventEmitter {
|
18 | readonly name: string;
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | constructor(name: string|JobCallback, job?: JobCallback|(() => void), callback?: () => void);
|
29 |
|
30 | /**
|
31 | * Adds an Invocation to this job. For internal use.
|
32 | * @internal
|
33 | * @return whether the invocation could be added
|
34 | */
|
35 | trackInvocation(invocation: Invocation): boolean;
|
36 |
|
37 | /**
|
38 | * removes an Invocation from this Job's tracking list. For internal use.
|
39 | * @internal
|
40 | * @return boolean whether the invocation was successful. Removing an Invocation that doesn't exist, returns false.
|
41 | */
|
42 | stopTrackingInvocation(invocation: Invocation): boolean;
|
43 |
|
44 | /**
|
45 | * @internal
|
46 | * @return the number of currently running instances of this Job.
|
47 | */
|
48 | triggeredJobs(): number;
|
49 |
|
50 | /**
|
51 | * set the number of currently running Jobs.
|
52 | * @internal
|
53 | */
|
54 | setTriggeredJobs(triggeredJobs: number): void;
|
55 |
|
56 | /**
|
57 | * cancel all pending Invocations of this Job.
|
58 | * @param reschedule whether to reschedule the canceled Invocations.
|
59 | */
|
60 | cancel(reschedule?: boolean): boolean;
|
61 |
|
62 | /**
|
63 | * cancel the next Invocation of this Job.
|
64 | * @param reschedule whether to reschedule the canceled Invocation.
|
65 | * @return whether cancelation was successful
|
66 | */
|
67 | cancelNext(reschedule?: boolean): boolean;
|
68 |
|
69 | /**
|
70 | * Changes the scheduling information for this Job.
|
71 | * @return whether the reschedule was successful
|
72 | */
|
73 | reschedule(spec: RecurrenceRule|string|number): boolean;
|
74 |
|
75 | /** The Date on which this Job will be run next. */
|
76 | nextInvocation(): Date;
|
77 |
|
78 | /** A list of all pending Invocations */
|
79 | pendingInvocations(): Invocation[];
|
80 |
|
81 | /**
|
82 | * run this Job immediately.
|
83 | */
|
84 | invoke(): void;
|
85 |
|
86 | /** schedule this Job to be run on the specified date. */
|
87 | runOnDate(date: Date): void;
|
88 |
|
89 | /** set scheduling information */
|
90 | schedule(date: Date|string|number): boolean;
|
91 | }
|
92 |
|
93 | export class Range {
|
94 | constructor(start?: number, end?: number, step?: number);
|
95 |
|
96 | /** Whether the class contains the specified value. */
|
97 | contains(value: number): boolean;
|
98 | }
|
99 |
|
100 | export type Recurrence = number | Range | string;
|
101 | export type RecurrenceSegment = Recurrence | Recurrence[];
|
102 | export type Timezone = string;
|
103 |
|
104 | export class RecurrenceRule {
|
105 | |
106 |
|
107 |
|
108 | date: RecurrenceSegment;
|
109 | dayOfWeek: RecurrenceSegment;
|
110 | hour: RecurrenceSegment;
|
111 | minute: RecurrenceSegment;
|
112 | month: RecurrenceSegment;
|
113 | second: RecurrenceSegment;
|
114 | year: RecurrenceSegment;
|
115 | tz: Timezone;
|
116 |
|
117 | constructor(
|
118 | year?: RecurrenceSegment,
|
119 | month?: RecurrenceSegment,
|
120 | date?: RecurrenceSegment,
|
121 | dayOfWeek?: RecurrenceSegment,
|
122 | hour?: RecurrenceSegment,
|
123 | minute?: RecurrenceSegment,
|
124 | second?: RecurrenceSegment,
|
125 | tz?: Timezone,
|
126 | );
|
127 |
|
128 | nextInvocationDate(base: Date): Date;
|
129 | }
|
130 |
|
131 | /**
|
132 | * Recurrence rule specification using a date range and cron expression.
|
133 | */
|
134 | export interface RecurrenceSpecDateRange {
|
135 | |
136 |
|
137 |
|
138 | start?: Date | string | number | undefined;
|
139 | |
140 |
|
141 |
|
142 | end?: Date | string | number | undefined;
|
143 | |
144 |
|
145 |
|
146 | rule: string;
|
147 | |
148 |
|
149 |
|
150 | tz?: Timezone | undefined;
|
151 | }
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | export interface RecurrenceSpecObjLit {
|
157 | |
158 |
|
159 |
|
160 | date?: RecurrenceSegment | undefined;
|
161 | dayOfWeek?: RecurrenceSegment | undefined;
|
162 | hour?: RecurrenceSegment | undefined;
|
163 | minute?: RecurrenceSegment | undefined;
|
164 | month?: RecurrenceSegment | undefined;
|
165 | second?: RecurrenceSegment | undefined;
|
166 | year?: RecurrenceSegment | undefined;
|
167 | |
168 |
|
169 |
|
170 | tz?: Timezone | undefined;
|
171 | }
|
172 |
|
173 | export class Invocation {
|
174 | fireDate: Date;
|
175 | job: Job;
|
176 | recurrenceRule: RecurrenceRule;
|
177 | timerID: number;
|
178 | constructor(job: Job, fireDate: Date, recurrenceRule: RecurrenceRule);
|
179 | }
|
180 |
|
181 | /**
|
182 | * Create a schedule job.
|
183 | *
|
184 | * @param name name for the new Job
|
185 | * @param rule scheduling info
|
186 | * @param callback callback to be executed on each invocation
|
187 | */
|
188 | export function scheduleJob(name: string, rule: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number, callback: JobCallback): Job;
|
189 |
|
190 | /**
|
191 | * Create a schedule job.
|
192 | *
|
193 | * @param rule scheduling info
|
194 | * @param callback callback to be executed on each invocation
|
195 | */
|
196 | export function scheduleJob(rule: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number, callback: JobCallback): Job;
|
197 |
|
198 | /**
|
199 | * Changes the timing of a Job, canceling all pending invocations.
|
200 | *
|
201 | * @param spec The new timing for this Job.
|
202 | * @return if the job could be rescheduled, {null} otherwise.
|
203 | */
|
204 | export function rescheduleJob(job: Job | string, spec: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string): Job;
|
205 |
|
206 |
|
207 | export let scheduledJobs: {[jobName: string]: Job};
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | export function cancelJob(job: Job|string): boolean;
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | export function gracefulShutdown(): Promise<void>;
|