forked from kelektiv/node-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.js
49 lines (44 loc) · 1.02 KB
/
cron.js
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
import Job from "./job"
import Time from "./time"
import * as luxon from "luxon/luxon"
import Timer from "timer";
globalThis.setInterval ??= Timer.repeat;
globalThis.clearInterval ??= Timer.clear;
globalThis.setTimeout ??= Timer.set;
globalThis.clearTimeout ??= Timer.clear;
luxon.DateTime.prototype.getWeekDay = function () {
return this.weekday === 7 ? 0 : this.weekday;
};
class Cron {
static spwan = function() {
throw new Error("unimplemented");
};
static CronTime = Time(luxon);
static CronJob = Job(this.CronTime, this.spawn);
static job = (
cronTime,
onTick,
onComplete,
startNow,
timeZone,
context,
runOnInit,
utcOffset,
unrefTimeout
) =>
new CronJob(
cronTime,
onTick,
onComplete,
startNow,
timeZone,
context,
runOnInit,
utcOffset,
unrefTimeout
);
static time = (cronTime, timeZone) => new CronTime(cronTime, timeZone);
static sendAt = cronTime => Cron.time(cronTime).sendAt();
static timeout = cronTime => Cron.time(cronTime).getTimeout();
}
export default Cron;