@stacksjs/scheduler 0.66.0 → 0.67.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/index.js +2 -5
- package/package.json +3 -5
- package/dist/index.js.map +0 -18
- package/src/cron.ts +0 -11
- package/src/index.ts +0 -7
- package/src/schedule.ts +0 -151
- package/src/types.ts +0 -3
package/src/cron.ts
DELETED
package/src/index.ts
DELETED
package/src/schedule.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { DateTime } from 'luxon'
|
|
2
|
-
import { log, runCommand } from '@stacksjs/cli'
|
|
3
|
-
import { CronJob, CronTime } from './'
|
|
4
|
-
|
|
5
|
-
export class Schedule {
|
|
6
|
-
private cronPattern = ''
|
|
7
|
-
private timezone = 'America/Los_Angeles'
|
|
8
|
-
private readonly task: () => void
|
|
9
|
-
// private cmd?: string
|
|
10
|
-
|
|
11
|
-
constructor(task: () => void) {
|
|
12
|
-
this.task = task
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
everySecond(): Schedule {
|
|
16
|
-
this.cronPattern = '* * * * * *'
|
|
17
|
-
return this
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
everyMinute(): Schedule {
|
|
21
|
-
this.cronPattern = '0 * * * * *'
|
|
22
|
-
return this
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
everyTwoMinutes(): Schedule {
|
|
26
|
-
this.cronPattern = '*/2 * * * * *'
|
|
27
|
-
return this
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
everyFiveMinutes(): Schedule {
|
|
31
|
-
this.cronPattern = '*/5 * * * *'
|
|
32
|
-
return this
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
everyTenMinutes(): Schedule {
|
|
36
|
-
this.cronPattern = '*/10 * * * *'
|
|
37
|
-
return this
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
everyThirtyMinutes(): Schedule {
|
|
41
|
-
this.cronPattern = '*/30 * * * *'
|
|
42
|
-
return this
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
everyHour(): Schedule {
|
|
46
|
-
this.cronPattern = '0 0 * * * *'
|
|
47
|
-
return this
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
everyDay(): Schedule {
|
|
51
|
-
this.cronPattern = '0 0 0 * * *'
|
|
52
|
-
return this
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
hourly(): Schedule {
|
|
56
|
-
this.cronPattern = '0 0 * * * *'
|
|
57
|
-
return this
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
daily(): Schedule {
|
|
61
|
-
this.cronPattern = '0 0 0 * * *'
|
|
62
|
-
return this
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
weekly(): Schedule {
|
|
66
|
-
this.cronPattern = '0 0 0 * * 0'
|
|
67
|
-
return this
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
monthly(): Schedule {
|
|
71
|
-
this.cronPattern = '0 0 0 1 * *'
|
|
72
|
-
return this
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
yearly(): Schedule {
|
|
76
|
-
this.cronPattern = '0 0 0 1 1 *'
|
|
77
|
-
return this
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
onDays(days: number[]): Schedule {
|
|
81
|
-
const dayPattern = days.join(',')
|
|
82
|
-
this.cronPattern = `0 0 0 * * ${dayPattern}`
|
|
83
|
-
return this
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// between(startTime: string, endTime: string) {
|
|
87
|
-
// // This method is a placeholder. Actual implementation will vary based on requirements.
|
|
88
|
-
// // Cron does not directly support "between" times without additional logic.
|
|
89
|
-
// console.warn('The "between" method is not directly supported by cron patterns and requires additional logic.')
|
|
90
|
-
// return this
|
|
91
|
-
// }
|
|
92
|
-
|
|
93
|
-
at(time: string): Schedule {
|
|
94
|
-
// Assuming time is in "HH:MM" format
|
|
95
|
-
const [hour, minute] = time.split(':').map(Number)
|
|
96
|
-
this.cronPattern = `${minute} ${hour} * * *`
|
|
97
|
-
return this
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setTimeZone(timezone: string): Schedule {
|
|
101
|
-
this.timezone = timezone
|
|
102
|
-
return this
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
start(): void {
|
|
106
|
-
// eslint-disable-next-line no-new
|
|
107
|
-
new CronJob(this.cronPattern, this.task, null, true, this.timezone)
|
|
108
|
-
log.info(`Scheduled task with pattern: ${this.cronPattern} in timezone: ${this.timezone}`)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// job and action methods need to be added and they accept a path string param
|
|
112
|
-
job(path: string): Schedule {
|
|
113
|
-
log.info(`Scheduling job: ${path}`)
|
|
114
|
-
return this
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
action(path: string): Schedule {
|
|
118
|
-
log.info(`Scheduling action: ${path}`)
|
|
119
|
-
return this
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static command(cmd: string): Schedule {
|
|
123
|
-
log.info(`Executing command: ${cmd}`)
|
|
124
|
-
return new Schedule(async () => {
|
|
125
|
-
log.info(`Executing command: ${cmd}`)
|
|
126
|
-
|
|
127
|
-
const result = await runCommand(cmd)
|
|
128
|
-
|
|
129
|
-
if (result.isErr()) {
|
|
130
|
-
log.error(result.error)
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
log.info(result.value)
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export class Job extends Schedule {}
|
|
140
|
-
|
|
141
|
-
export function sendAt(cronTime: string | Date | DateTime): DateTime {
|
|
142
|
-
return new CronTime(cronTime).sendAt()
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function timeout(cronTime: string | Date | DateTime): number {
|
|
146
|
-
return new CronTime(cronTime).getTimeout()
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export type Scheduler = typeof Schedule
|
|
150
|
-
|
|
151
|
-
export default Schedule
|
package/src/types.ts
DELETED