-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.d.ts
99 lines (88 loc) · 2.67 KB
/
index.d.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { ServiceSchema, Context } from "moleculer";
import { CronJob as NodeCronJob, CronTime as NodeCronTime } from "cron";
declare module "moleculer" {
interface ServiceSettingsSchema {
cronJobs?: CronJobConfig[];
}
interface Service {
jobs?: Map<string, CronJobWrapper>;
}
}
export interface CronJobConfig {
name: string;
cronTime: string | Date;
onTick: (this: Context) => void | Promise<void>;
onComplete?: (this: Context) => void;
start?: boolean;
timeZone?: string | null;
context?: any;
onJobInitialised?: (this: Context) => void;
utcOffset?: number | null;
unrefTimeout?: boolean | null;
}
export interface CronJob {
start: () => void;
stop: () => void;
lastDate: () => Date;
nextDates: (count: number) => Date[];
fireOnTick: () => void;
addCallback: (callback: () => void) => void;
running: boolean;
cronTime: CronTime;
}
export interface CronTime {
source: string;
zone: string;
_fields: number[];
_tz: string;
_utc: boolean;
_offsets: number[];
}
export interface CronJobWrapper {
cronJob: CronJob;
startJob: () => void;
stopJob: () => void;
lastDate: () => Date;
running: () => boolean;
setTime: (cronTime: string | Date) => void;
nextDates: (count: number) => Date[];
addCallback: (callback: () => void) => void;
manualStart: boolean;
}
export interface CronMixinSchema extends ServiceSchema {
settings?: {
cronJobs?: CronJobConfig[];
};
methods: {
validateAndCreateJobs: () => void;
createJob: (jobConfig: CronJobConfig) => void;
wrapOnTick: (jobName: string, onTick: CronJobConfig['onTick']) => () => Promise<void>;
wrapOnComplete: (jobName: string, onComplete?: CronJobConfig['onComplete']) => () => void;
startJobs: () => void;
startJob: (name: string) => void;
stopJob: (name: string) => void;
getJob: (name: string) => CronJobWrapper | undefined;
getCronTime: (time: string | Date) => CronTime;
};
}
declare const CronMixin: CronMixinSchema;
export default CronMixin;
// Extend the 'cron' module declarations
declare module "cron" {
export class CronJob implements CronJob {
constructor(
cronTime: string | Date,
onTick: () => void,
onComplete?: () => void,
start?: boolean,
timeZone?: string,
context?: any,
runOnInit?: boolean,
utcOffset?: number,
unrefTimeout?: boolean
);
}
export class CronTime implements CronTime {
constructor(time: string | Date, zone?: string, utcOffset?: number);
}
}