-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathschedule.ts
52 lines (45 loc) · 1.23 KB
/
schedule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { ICronJobConfig } from './interfaces/cron-job-config.interface';
import { IJobConfig } from './interfaces/job-config.interface';
import { Scheduler } from './scheduler';
import { IGlobalConfig } from './interfaces/global-config.interface';
import { defaults } from './defaults';
export class Schedule {
private readonly scheduler = Scheduler;
constructor(globalConfig?: IGlobalConfig) {
if (globalConfig) {
for (const key in globalConfig) {
defaults[key] = globalConfig[key];
}
}
}
public cancelJob(key: string) {
this.scheduler.cancelJob(key);
}
public cancelJobs() {
this.scheduler.cancelJobs();
}
public scheduleCronJob(
key: string,
cron: string,
callback: JobCallback,
config?: ICronJobConfig,
) {
this.scheduler.scheduleCronJob(key, cron, callback, config);
}
public scheduleIntervalJob(
key: string,
interval: number,
callback: JobCallback,
config?: IJobConfig,
) {
this.scheduler.scheduleIntervalJob(key, interval, callback, config);
}
public scheduleTimeoutJob(
key: string,
timeout: number,
callback: JobCallback,
config?: IJobConfig,
) {
this.scheduler.scheduleTimeoutJob(key, timeout, callback, config);
}
}