@stacksjs/scheduler 0.67.0 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cron.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/schedule.d.ts +126 -27
- package/dist/types.d.ts +3 -4
- package/package.json +1 -1
package/dist/cron.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export { CronJob, CronTime } from
|
|
1
|
+
export type {;
|
|
2
|
+
export { CronJob, CronTime } from 'cron'
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from './cron'
|
|
2
|
+
export * from './schedule'
|
|
3
|
+
export * from './types'
|
package/dist/schedule.d.ts
CHANGED
|
@@ -1,32 +1,131 @@
|
|
|
1
|
-
import type { DateTime } from
|
|
1
|
+
import type { DateTime } from 'luxon';
|
|
2
|
+
|
|
2
3
|
export declare class Schedule {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
private cronPattern = ''
|
|
5
|
+
private timezone = 'America/Los_Angeles'
|
|
6
|
+
private readonly task: () => void
|
|
7
|
+
|
|
8
|
+
constructor(task: () => void) {
|
|
9
|
+
this.task = task
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
everySecond(): Schedule {
|
|
13
|
+
this.cronPattern = '* * * * * *'
|
|
14
|
+
return this
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
everyMinute(): Schedule {
|
|
18
|
+
this.cronPattern = '0 * * * * *'
|
|
19
|
+
return this
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
everyTwoMinutes(): Schedule {
|
|
23
|
+
this.cronPattern = '*/2 * * * * *'
|
|
24
|
+
return this
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
everyFiveMinutes(): Schedule {
|
|
28
|
+
this.cronPattern = '*/5 * * * *'
|
|
29
|
+
return this
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
everyTenMinutes(): Schedule {
|
|
33
|
+
this.cronPattern = '*/10 * * * *'
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
everyThirtyMinutes(): Schedule {
|
|
38
|
+
this.cronPattern = '*/30 * * * *'
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
everyHour(): Schedule {
|
|
43
|
+
this.cronPattern = '0 0 * * * *'
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
everyDay(): Schedule {
|
|
48
|
+
this.cronPattern = '0 0 0 * * *'
|
|
49
|
+
return this
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
hourly(): Schedule {
|
|
53
|
+
this.cronPattern = '0 0 * * * *'
|
|
54
|
+
return this
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
daily(): Schedule {
|
|
58
|
+
this.cronPattern = '0 0 0 * * *'
|
|
59
|
+
return this
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
weekly(): Schedule {
|
|
63
|
+
this.cronPattern = '0 0 0 * * 0'
|
|
64
|
+
return this
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
monthly(): Schedule {
|
|
68
|
+
this.cronPattern = '0 0 0 1 * *'
|
|
69
|
+
return this
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
yearly(): Schedule {
|
|
73
|
+
this.cronPattern = '0 0 0 1 1 *'
|
|
74
|
+
return this
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onDays(days: number[]): Schedule {
|
|
78
|
+
const dayPattern = days.join(',')
|
|
79
|
+
this.cronPattern = `0 0 0 * * ${dayPattern}`
|
|
80
|
+
return this
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
at(time: string): Schedule {
|
|
85
|
+
const [hour, minute] = time.split(':').map(Number)
|
|
86
|
+
this.cronPattern = `${minute} ${hour} * * *`
|
|
87
|
+
return this
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setTimeZone(timezone: string): Schedule {
|
|
91
|
+
this.timezone = timezone
|
|
92
|
+
return this
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
start(): void {
|
|
96
|
+
new CronJob(this.cronPattern, this.task, null, true, this.timezone)
|
|
97
|
+
log.info(`Scheduled task with pattern: ${this.cronPattern} in timezone: ${this.timezone}`)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
job(path: string): Schedule {
|
|
101
|
+
log.info(`Scheduling job: ${path}`)
|
|
102
|
+
return this
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
action(path: string): Schedule {
|
|
106
|
+
log.info(`Scheduling action: ${path}`)
|
|
107
|
+
return this
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static command(cmd: string): Schedule {
|
|
111
|
+
log.info(`Executing command: ${cmd}`)
|
|
112
|
+
return new Schedule(async () => {
|
|
113
|
+
log.info(`Executing command: ${cmd}`)
|
|
114
|
+
|
|
115
|
+
const result = await runCommand(cmd)
|
|
116
|
+
|
|
117
|
+
if (result.isErr()) {
|
|
118
|
+
log.error(result.error)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
log.info(result.value)
|
|
123
|
+
})
|
|
124
|
+
}
|
|
27
125
|
}
|
|
28
126
|
export declare class Job extends Schedule {}
|
|
29
127
|
export declare function sendAt(cronTime: string | Date | DateTime): DateTime;
|
|
30
128
|
export declare function timeout(cronTime: string | Date | DateTime): number;
|
|
31
|
-
export type Scheduler = typeof Schedule
|
|
32
|
-
|
|
129
|
+
export declare type Scheduler = typeof Schedule
|
|
130
|
+
|
|
131
|
+
export default Schedule;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type IntRange<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
> = number extends Min | Max ? never : number | [Min | number, Max | number];
|
|
1
|
+
export declare type IntRange<Min extends number, Max extends number> = number extends Min | Max
|
|
2
|
+
? never
|
|
3
|
+
: number | [Min | number, Max | number]
|