@stacksjs/scheduler 0.58.51 → 0.58.52
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/index.js +682 -152
- package/package.json +7 -4
- package/src/constants.ts +81 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +15 -317
- package/src/job.ts +315 -0
- package/src/schedule.ts +111 -0
- package/src/time.ts +823 -0
- package/src/types/cron.ts +98 -0
- package/src/types/utils.ts +14 -0
- package/src/utils.ts +19 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/scheduler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.58.
|
|
4
|
+
"version": "0.58.52",
|
|
5
5
|
"description": "The Stacks scheduler.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
19
|
"scheduler",
|
|
20
|
+
"node-cron",
|
|
21
|
+
"jobs",
|
|
22
|
+
"bun",
|
|
20
23
|
"stacks"
|
|
21
24
|
],
|
|
22
25
|
"exports": {
|
|
@@ -45,13 +48,13 @@
|
|
|
45
48
|
"prepublishOnly": "bun --bun run build"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
|
-
"
|
|
51
|
+
"luxon": "^3.4.4"
|
|
49
52
|
},
|
|
50
53
|
"dependencies": {
|
|
51
|
-
"
|
|
54
|
+
"luxon": "^3.4.4"
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
54
57
|
"@stacksjs/development": "latest",
|
|
55
|
-
"
|
|
58
|
+
"sinon": "^17.0.1"
|
|
56
59
|
}
|
|
57
60
|
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const CONSTRAINTS = Object.freeze({
|
|
2
|
+
second: [0, 59],
|
|
3
|
+
minute: [0, 59],
|
|
4
|
+
hour: [0, 23],
|
|
5
|
+
dayOfMonth: [1, 31],
|
|
6
|
+
month: [1, 12],
|
|
7
|
+
dayOfWeek: [0, 7],
|
|
8
|
+
} as const)
|
|
9
|
+
export const MONTH_CONSTRAINTS = Object.freeze({
|
|
10
|
+
1: 31,
|
|
11
|
+
2: 29, // support leap year...not perfect
|
|
12
|
+
3: 31,
|
|
13
|
+
4: 30,
|
|
14
|
+
5: 31,
|
|
15
|
+
6: 30,
|
|
16
|
+
7: 31,
|
|
17
|
+
8: 31,
|
|
18
|
+
9: 30,
|
|
19
|
+
10: 31,
|
|
20
|
+
11: 30,
|
|
21
|
+
12: 31,
|
|
22
|
+
} as const)
|
|
23
|
+
export const PARSE_DEFAULTS = Object.freeze({
|
|
24
|
+
second: '0',
|
|
25
|
+
minute: '*',
|
|
26
|
+
hour: '*',
|
|
27
|
+
dayOfMonth: '*',
|
|
28
|
+
month: '*',
|
|
29
|
+
dayOfWeek: '*',
|
|
30
|
+
} as const)
|
|
31
|
+
export const ALIASES = Object.freeze({
|
|
32
|
+
jan: 1,
|
|
33
|
+
feb: 2,
|
|
34
|
+
mar: 3,
|
|
35
|
+
apr: 4,
|
|
36
|
+
may: 5,
|
|
37
|
+
jun: 6,
|
|
38
|
+
jul: 7,
|
|
39
|
+
aug: 8,
|
|
40
|
+
sep: 9,
|
|
41
|
+
oct: 10,
|
|
42
|
+
nov: 11,
|
|
43
|
+
dec: 12,
|
|
44
|
+
sun: 0,
|
|
45
|
+
mon: 1,
|
|
46
|
+
tue: 2,
|
|
47
|
+
wed: 3,
|
|
48
|
+
thu: 4,
|
|
49
|
+
fri: 5,
|
|
50
|
+
sat: 6,
|
|
51
|
+
} as const)
|
|
52
|
+
export const TIME_UNITS_MAP = Object.freeze({
|
|
53
|
+
SECOND: 'second',
|
|
54
|
+
MINUTE: 'minute',
|
|
55
|
+
HOUR: 'hour',
|
|
56
|
+
DAY_OF_MONTH: 'dayOfMonth',
|
|
57
|
+
MONTH: 'month',
|
|
58
|
+
DAY_OF_WEEK: 'dayOfWeek',
|
|
59
|
+
} as const)
|
|
60
|
+
export const TIME_UNITS = Object.freeze(Object.values(TIME_UNITS_MAP)) as [
|
|
61
|
+
'second',
|
|
62
|
+
'minute',
|
|
63
|
+
'hour',
|
|
64
|
+
'dayOfMonth',
|
|
65
|
+
'month',
|
|
66
|
+
'dayOfWeek',
|
|
67
|
+
]
|
|
68
|
+
export const TIME_UNITS_LEN: number = TIME_UNITS.length
|
|
69
|
+
export const PRESETS = Object.freeze({
|
|
70
|
+
'@yearly': '0 0 0 1 1 *',
|
|
71
|
+
'@monthly': '0 0 0 1 * *',
|
|
72
|
+
'@weekly': '0 0 0 * * 0',
|
|
73
|
+
'@daily': '0 0 0 * * *',
|
|
74
|
+
'@hourly': '0 0 * * * *',
|
|
75
|
+
'@minutely': '0 * * * * *',
|
|
76
|
+
'@secondly': '* * * * * *',
|
|
77
|
+
'@weekdays': '0 0 0 * * 1-5',
|
|
78
|
+
'@weekends': '0 0 0 * * 0,6',
|
|
79
|
+
} as const)
|
|
80
|
+
export const RE_WILDCARDS = /\*/g
|
|
81
|
+
export const RE_RANGE = /^(\d+)(?:-(\d+))?(?:\/(\d+))?$/g
|
package/src/errors.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,321 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Schedule } from './schedule'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// }
|
|
3
|
+
export { CronJob } from './job'
|
|
4
|
+
export { CronTime } from './time'
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
everyThirtyMinutes(): this
|
|
18
|
-
hourly(): this
|
|
19
|
-
daily(): this
|
|
20
|
-
twiceDaily(hour1: number, hour2: number): this
|
|
21
|
-
weekly(): this
|
|
22
|
-
monthly(): this
|
|
23
|
-
quarterly(): this
|
|
24
|
-
yearly(): this
|
|
25
|
-
weekdays(): this
|
|
26
|
-
weekends(): this
|
|
27
|
-
mondays(): this
|
|
28
|
-
tuesdays(): this
|
|
29
|
-
wednesdays(): this
|
|
30
|
-
thursdays(): this
|
|
31
|
-
fridays(): this
|
|
32
|
-
saturdays(): this
|
|
33
|
-
sundays(): this
|
|
34
|
-
between(startTime: string, endTime: string): this
|
|
35
|
-
timezone(timezone: string): this
|
|
36
|
-
when(callback: () => boolean): this
|
|
37
|
-
at(time: string): this
|
|
38
|
-
}
|
|
6
|
+
export type {
|
|
7
|
+
CronCallback,
|
|
8
|
+
CronCommand,
|
|
9
|
+
CronContext,
|
|
10
|
+
CronJobParams,
|
|
11
|
+
CronOnCompleteCallback,
|
|
12
|
+
CronOnCompleteCommand,
|
|
13
|
+
Ranges,
|
|
14
|
+
TimeUnit,
|
|
15
|
+
} from './types/cron'
|
|
39
16
|
|
|
40
|
-
export
|
|
41
|
-
private actionName: string = ''
|
|
42
|
-
private commandName: string = ''
|
|
43
|
-
private jobName: string = ''
|
|
44
|
-
private execName: string = ''
|
|
45
|
-
private callback: () => void = () => {}
|
|
46
|
-
private whenCallback: () => boolean = () => true
|
|
47
|
-
private startTime: string = ''
|
|
48
|
-
private endTime: string = ''
|
|
49
|
-
private timezoneName: string = ''
|
|
50
|
-
private time: string = ''
|
|
17
|
+
export * from './schedule'
|
|
51
18
|
|
|
52
|
-
|
|
53
|
-
this.actionName = action
|
|
54
|
-
return this
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
command(cmd: string): this {
|
|
58
|
-
this.commandName = cmd
|
|
59
|
-
return this
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
job(job: string): this {
|
|
63
|
-
this.jobName = job
|
|
64
|
-
return this
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
exec(cmd: string): this {
|
|
68
|
-
this.execName = cmd
|
|
69
|
-
return this
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
call(callback: () => void): this {
|
|
73
|
-
this.callback = callback
|
|
74
|
-
return this
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
everyMinute(): this {
|
|
78
|
-
// implementation here
|
|
79
|
-
return this
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
everySecond(): this {
|
|
83
|
-
// implementation here
|
|
84
|
-
return this
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
everyFiveMinutes(): this {
|
|
88
|
-
// implementation here
|
|
89
|
-
return this
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
everyTenMinutes(): this {
|
|
93
|
-
// implementation here
|
|
94
|
-
return this
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
everyThirtyMinutes(): this {
|
|
98
|
-
// implementation here
|
|
99
|
-
return this
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
hourly(): this {
|
|
103
|
-
// implementation here
|
|
104
|
-
return this
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
daily(): this {
|
|
108
|
-
// implementation here
|
|
109
|
-
return this
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
twiceDaily(_hour1: number, _hour2: number): this {
|
|
113
|
-
// implementation here
|
|
114
|
-
return this
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
weekly(): this {
|
|
118
|
-
// implementation here
|
|
119
|
-
return this
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
monthly(): this {
|
|
123
|
-
// implementation here
|
|
124
|
-
return this
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
quarterly(): this {
|
|
128
|
-
// implementation here
|
|
129
|
-
return this
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
yearly(): this {
|
|
133
|
-
// implementation here
|
|
134
|
-
return this
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
weekdays(): this {
|
|
138
|
-
// implementation here
|
|
139
|
-
return this
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
weekends(): this {
|
|
143
|
-
// implementation here
|
|
144
|
-
return this
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
mondays(): this {
|
|
148
|
-
// implementation here
|
|
149
|
-
return this
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
tuesdays(): this {
|
|
153
|
-
// implementation here
|
|
154
|
-
return this
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
wednesdays(): this {
|
|
158
|
-
// implementation here
|
|
159
|
-
return this
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
thursdays(): this {
|
|
163
|
-
// implementation here
|
|
164
|
-
return this
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
fridays(): this {
|
|
168
|
-
// implementation here
|
|
169
|
-
return this
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
saturdays(): this {
|
|
173
|
-
// implementation here
|
|
174
|
-
return this
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
sundays(): this {
|
|
178
|
-
// implementation here
|
|
179
|
-
return this
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
between(startTime: string, endTime: string): this {
|
|
183
|
-
this.startTime = startTime
|
|
184
|
-
this.endTime = endTime
|
|
185
|
-
return this
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
timezone(timezone: string): this {
|
|
189
|
-
this.timezoneName = timezone
|
|
190
|
-
return this
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
when(callback: () => boolean): this {
|
|
194
|
-
this.whenCallback = callback
|
|
195
|
-
return this
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
at(time: string): this {
|
|
199
|
-
this.time = time
|
|
200
|
-
return this
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export interface Scheduler {
|
|
205
|
-
everySecond: () => void
|
|
206
|
-
everySeconds: (seconds: number) => void
|
|
207
|
-
everyMinute: () => void
|
|
208
|
-
everyMinutes: (minutes: number) => void
|
|
209
|
-
everyTwoMinutes: () => void
|
|
210
|
-
everyThreeMinutes: () => void
|
|
211
|
-
everyFourMinutes: () => void
|
|
212
|
-
everyFiveMinutes: () => void
|
|
213
|
-
everyTenMinutes: () => void
|
|
214
|
-
everyFifteenMinutes: () => void
|
|
215
|
-
everyThirtyMinutes: () => void
|
|
216
|
-
hourly: () => void
|
|
217
|
-
hourlyAt: (minute: number) => void
|
|
218
|
-
everyOddHour: () => void
|
|
219
|
-
everyHours: (hours: number) => void
|
|
220
|
-
everyTwoHours: () => void
|
|
221
|
-
everyThreeHours: () => void
|
|
222
|
-
everyFourHours: () => void
|
|
223
|
-
everySixHours: () => void
|
|
224
|
-
daily: () => void
|
|
225
|
-
dailyAt: (hour: number, minute: number) => void
|
|
226
|
-
everyDays: (days: number) => void
|
|
227
|
-
weekly: () => void
|
|
228
|
-
quarterly: () => void
|
|
229
|
-
yearly: () => void
|
|
230
|
-
cron: (interval: string, timezone?: string) => void
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// function run(callback: Function): Scheduler {
|
|
234
|
-
export function run(callback: ((now: Date | 'manual' | 'init') => void) | string): Scheduler {
|
|
235
|
-
return {
|
|
236
|
-
everySecond: () => {
|
|
237
|
-
cron.schedule('* * * * * *', callback)
|
|
238
|
-
},
|
|
239
|
-
everySeconds: (seconds = 1) => {
|
|
240
|
-
cron.schedule(`*/${seconds} * * * * *`, callback)
|
|
241
|
-
},
|
|
242
|
-
everyMinute: () => {
|
|
243
|
-
cron.schedule('* * * * *', callback)
|
|
244
|
-
},
|
|
245
|
-
everyTwoMinutes: () => {
|
|
246
|
-
cron.schedule('*/2 * * * *', callback)
|
|
247
|
-
},
|
|
248
|
-
everyThreeMinutes: () => {
|
|
249
|
-
cron.schedule('*/3 * * * *', callback)
|
|
250
|
-
},
|
|
251
|
-
everyFourMinutes: () => {
|
|
252
|
-
cron.schedule('*/4 * * * *', callback)
|
|
253
|
-
},
|
|
254
|
-
everyFiveMinutes: () => {
|
|
255
|
-
cron.schedule('*/5 * * * *', callback)
|
|
256
|
-
},
|
|
257
|
-
everyTenMinutes: () => {
|
|
258
|
-
cron.schedule('*/10 * * * *', callback)
|
|
259
|
-
},
|
|
260
|
-
everyFifteenMinutes: () => {
|
|
261
|
-
cron.schedule('*/15 * * * *', callback)
|
|
262
|
-
},
|
|
263
|
-
everyThirtyMinutes: () => {
|
|
264
|
-
cron.schedule('*/30 * * * *', callback)
|
|
265
|
-
},
|
|
266
|
-
everyMinutes: (minutes: number) => {
|
|
267
|
-
cron.schedule(`*/${minutes} * * * *`, callback)
|
|
268
|
-
},
|
|
269
|
-
hourly: () => {
|
|
270
|
-
cron.schedule('0 * * * *', callback)
|
|
271
|
-
},
|
|
272
|
-
everyHours: (hours: number) => {
|
|
273
|
-
cron.schedule(`0 */${hours} * * *`, callback)
|
|
274
|
-
},
|
|
275
|
-
hourlyAt: (minute: number) => {
|
|
276
|
-
cron.schedule(`${minute} * * * *`, callback)
|
|
277
|
-
},
|
|
278
|
-
everyOddHour: () => {
|
|
279
|
-
cron.schedule('0 */2 * * *', callback)
|
|
280
|
-
},
|
|
281
|
-
everyTwoHours: () => {
|
|
282
|
-
cron.schedule('0 */2 * * *', callback)
|
|
283
|
-
},
|
|
284
|
-
everyThreeHours: () => {
|
|
285
|
-
cron.schedule('0 */3 * * *', callback)
|
|
286
|
-
},
|
|
287
|
-
everyFourHours: () => {
|
|
288
|
-
cron.schedule('0 */4 * * *', callback)
|
|
289
|
-
},
|
|
290
|
-
everySixHours: () => {
|
|
291
|
-
cron.schedule('0 */6 * * *', callback)
|
|
292
|
-
},
|
|
293
|
-
dailyAt: (hour: number, minute: number) => {
|
|
294
|
-
cron.schedule(`${minute} ${hour} * * *`, callback)
|
|
295
|
-
},
|
|
296
|
-
daily: () => {
|
|
297
|
-
cron.schedule('0 0 * * *', callback)
|
|
298
|
-
},
|
|
299
|
-
everyDays: (days: number) => {
|
|
300
|
-
cron.schedule(`0 0 */${days} * *`, callback)
|
|
301
|
-
},
|
|
302
|
-
weekly: () => {
|
|
303
|
-
cron.schedule('0 0 * * 0', callback)
|
|
304
|
-
},
|
|
305
|
-
quarterly: () => {
|
|
306
|
-
cron.schedule('0 0 1 */3 *', callback)
|
|
307
|
-
},
|
|
308
|
-
yearly: () => {
|
|
309
|
-
cron.schedule('0 0 1 1 *', callback)
|
|
310
|
-
},
|
|
311
|
-
cron: (interval: string, timezone?: string) => {
|
|
312
|
-
timezone ? cron.schedule(interval, callback, { scheduled: true, timezone }) : cron.schedule(interval, callback)
|
|
313
|
-
},
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export function useScheduler() {
|
|
318
|
-
return {
|
|
319
|
-
run,
|
|
320
|
-
}
|
|
321
|
-
}
|
|
19
|
+
export default Schedule
|