@zerotal/scheduler 1.6.3 → 1.7.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/api-surface.md +236 -0
- package/package.json +3 -2
package/api-surface.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# @zerotal/scheduler — public API surface
|
|
2
|
+
|
|
3
|
+
<!-- AUTO-GENERATED by scripts/api-surface.ts. Do not edit by hand.
|
|
4
|
+
Run `bun run api:surface` to regenerate after an intentional API change. -->
|
|
5
|
+
|
|
6
|
+
## . `(./src/index.ts)`
|
|
7
|
+
|
|
8
|
+
class CronExpression = {
|
|
9
|
+
new (expression?: string): CronExpression
|
|
10
|
+
static describe: (expression: string) => string
|
|
11
|
+
static isValid: (expression: string) => boolean
|
|
12
|
+
static nextRunAfter: (expression: string, from?: Date) => Date | null
|
|
13
|
+
static readonly SEARCH_HORIZON_DAYS: number
|
|
14
|
+
dayOfMonth: (v: number | string) => CronExpression
|
|
15
|
+
hour: (v: number | string) => CronExpression
|
|
16
|
+
matches: (date?: Date) => boolean
|
|
17
|
+
minute: (v: number | string) => CronExpression
|
|
18
|
+
month: (v: number | string) => CronExpression
|
|
19
|
+
nextRun: (from?: Date) => Date | null
|
|
20
|
+
toString: () => string
|
|
21
|
+
weekday: (v: number | string) => CronExpression
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class FileScheduleRunStore = {
|
|
25
|
+
new (_path: string, _keep?: number): FileScheduleRunStore
|
|
26
|
+
lastFor: (name: string) => ScheduleRunRecord | undefined
|
|
27
|
+
recent: (limit?: number, name?: string) => ScheduleRunRecord[]
|
|
28
|
+
record: (run: ScheduleRunRecord) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class Schedule = {
|
|
32
|
+
new (): Schedule
|
|
33
|
+
appendOutputTo?: string
|
|
34
|
+
between?: [string, string]
|
|
35
|
+
cron?: string
|
|
36
|
+
emailOutputTo?: string
|
|
37
|
+
environments?: string[]
|
|
38
|
+
frequency?: (every: SchedulerBuilder) => ScheduledTask
|
|
39
|
+
handle: () => void | Promise<void>
|
|
40
|
+
inBackground?: boolean
|
|
41
|
+
name?: string
|
|
42
|
+
pingAfter?: string
|
|
43
|
+
pingBefore?: string
|
|
44
|
+
pingOnFailure?: string
|
|
45
|
+
pingOnSuccess?: string
|
|
46
|
+
skip?: () => boolean | Promise<boolean>
|
|
47
|
+
timezone?: string
|
|
48
|
+
unlessBetween?: [string, string]
|
|
49
|
+
when?: () => boolean | Promise<boolean>
|
|
50
|
+
withoutOverlapping?: boolean | OverlapLockOptions
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
class ScheduledTask = {
|
|
54
|
+
new (name: string, schedule: string, callback: TaskCallback): ScheduledTask
|
|
55
|
+
static lockManager: LockManager | null
|
|
56
|
+
static outputMailer: OutputMailer | undefined
|
|
57
|
+
appendOutputTo: (path: string) => ScheduledTask
|
|
58
|
+
at: (time: string) => ScheduledTask
|
|
59
|
+
between: (start: string, end: string) => ScheduledTask
|
|
60
|
+
emailOutputTo: (email: string) => ScheduledTask
|
|
61
|
+
environments: (envs: string[]) => ScheduledTask
|
|
62
|
+
isRunning: boolean
|
|
63
|
+
lastDurationMs: number | undefined
|
|
64
|
+
lastOk: boolean | undefined
|
|
65
|
+
lastRunAt: Date | undefined
|
|
66
|
+
name: string
|
|
67
|
+
nextRunAt: (from?: Date) => Date | null
|
|
68
|
+
onFailure: (fn: (err: Error) => void | Promise<void>) => ScheduledTask
|
|
69
|
+
onStart: (fn: TaskHook) => ScheduledTask
|
|
70
|
+
onSuccess: (fn: () => void | Promise<void>) => ScheduledTask
|
|
71
|
+
pingAfter: (url: string) => ScheduledTask
|
|
72
|
+
pingBefore: (url: string) => ScheduledTask
|
|
73
|
+
pingOnFailure: (url: string) => ScheduledTask
|
|
74
|
+
pingOnSuccess: (url: string) => ScheduledTask
|
|
75
|
+
runInBackground: () => ScheduledTask
|
|
76
|
+
runNow: () => Promise<void>
|
|
77
|
+
schedule: string
|
|
78
|
+
sendOutputTo: (path: string) => ScheduledTask
|
|
79
|
+
skip: (predicate: TaskGuard) => ScheduledTask
|
|
80
|
+
start: () => void
|
|
81
|
+
stop: () => void
|
|
82
|
+
timezone: (tz: string) => ScheduledTask
|
|
83
|
+
unlessBetween: (start: string, end: string) => ScheduledTask
|
|
84
|
+
when: (predicate: TaskGuard) => ScheduledTask
|
|
85
|
+
withoutOverlapping: (options?: OverlapLockOptions) => ScheduledTask
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class SchedulerBuilder = {
|
|
89
|
+
new (_manager: SchedulerManager, _name: string, _callback: TaskCallback): SchedulerBuilder
|
|
90
|
+
cron: (expression: string) => ScheduledTask
|
|
91
|
+
daily: () => ScheduledTask
|
|
92
|
+
dailyAt: (time: string) => ScheduledTask
|
|
93
|
+
days: (daysOfWeek: number[]) => ScheduledTask
|
|
94
|
+
everyFifteenMinutes: () => ScheduledTask
|
|
95
|
+
everyFiveMinutes: () => ScheduledTask
|
|
96
|
+
everyFiveSeconds: () => ScheduledTask
|
|
97
|
+
everyFourMinutes: () => ScheduledTask
|
|
98
|
+
everyMinute: () => ScheduledTask
|
|
99
|
+
everyOddHour: () => ScheduledTask
|
|
100
|
+
everySecond: () => ScheduledTask
|
|
101
|
+
everyTenMinutes: () => ScheduledTask
|
|
102
|
+
everyTenSeconds: () => ScheduledTask
|
|
103
|
+
everyThirtyMinutes: () => ScheduledTask
|
|
104
|
+
everyThirtySeconds: () => ScheduledTask
|
|
105
|
+
everyThreeMinutes: () => ScheduledTask
|
|
106
|
+
everyTwoMinutes: () => ScheduledTask
|
|
107
|
+
everyTwoSeconds: () => ScheduledTask
|
|
108
|
+
fridays: () => ScheduledTask
|
|
109
|
+
hourly: () => ScheduledTask
|
|
110
|
+
hourlyAt: (minute: number) => ScheduledTask
|
|
111
|
+
lastDayOfMonth: (time?: string) => ScheduledTask
|
|
112
|
+
mondays: () => ScheduledTask
|
|
113
|
+
monthly: () => ScheduledTask
|
|
114
|
+
quarterly: () => ScheduledTask
|
|
115
|
+
quarterlyOn: (dayOfMonth?: number, time?: string) => ScheduledTask
|
|
116
|
+
saturdays: () => ScheduledTask
|
|
117
|
+
sundays: () => ScheduledTask
|
|
118
|
+
thursdays: () => ScheduledTask
|
|
119
|
+
tuesdays: () => ScheduledTask
|
|
120
|
+
twiceDaily: (first?: number, second?: number) => ScheduledTask
|
|
121
|
+
twiceMonthly: (first?: number, second?: number) => ScheduledTask
|
|
122
|
+
twiceWeekly: (first?: number, second?: number) => ScheduledTask
|
|
123
|
+
wednesdays: () => ScheduledTask
|
|
124
|
+
weekdays: () => ScheduledTask
|
|
125
|
+
weekends: () => ScheduledTask
|
|
126
|
+
weekly: () => ScheduledTask
|
|
127
|
+
yearly: () => ScheduledTask
|
|
128
|
+
yearlyOn: (month?: number, dayOfMonth?: number, time?: string) => ScheduledTask
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class SchedulerManager = {
|
|
132
|
+
new (): SchedulerManager
|
|
133
|
+
add: (name: string, cronExpression: string, callback: TaskCallback) => ScheduledTask
|
|
134
|
+
job: (name: string, callback: TaskCallback) => SchedulerBuilder
|
|
135
|
+
readonly staticConfigFindings: { className: string; keys: string[];}[]
|
|
136
|
+
start: () => void
|
|
137
|
+
stop: () => void
|
|
138
|
+
tasks: ReadonlyMap<string, ScheduledTask>
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
class SchedulerProvider = {
|
|
142
|
+
new (app: Application): SchedulerProvider
|
|
143
|
+
static dependsOn?: (new (app: Application) => ServiceProvider)[]
|
|
144
|
+
static environments: AppEnvironment[]
|
|
145
|
+
static priority?: number
|
|
146
|
+
static provides: readonly ['scheduler']
|
|
147
|
+
devProcesses: () => DevProcessDefinition[]
|
|
148
|
+
doctorChecks: () => DoctorCheck[]
|
|
149
|
+
onBooted: () => Promise<void>
|
|
150
|
+
onBooting: () => Promise<void>
|
|
151
|
+
onRegister: () => void
|
|
152
|
+
onRequestProcessed: (_ctx: HttpContext) => Promise<void>
|
|
153
|
+
onRequestReceived: (_ctx: HttpContext) => Promise<void>
|
|
154
|
+
onResponseSent: (_ctx: HttpContext) => Promise<void>
|
|
155
|
+
onStarted: () => Promise<void>
|
|
156
|
+
onStarting: () => Promise<void>
|
|
157
|
+
onStopped: () => Promise<void>
|
|
158
|
+
onStopping: () => Promise<void>
|
|
159
|
+
replContext: () => Record<string, unknown>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
class TaskFailed = {
|
|
163
|
+
new (name: string, durationMs: number, error: string): TaskFailed
|
|
164
|
+
readonly durationMs: number
|
|
165
|
+
readonly error: string
|
|
166
|
+
readonly name: string
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
class TaskRan = {
|
|
170
|
+
new (name: string, durationMs: number, ok: boolean): TaskRan
|
|
171
|
+
readonly durationMs: number
|
|
172
|
+
readonly name: string
|
|
173
|
+
readonly ok: boolean
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
class TaskSkipped = {
|
|
177
|
+
new (name: string, reason: 'env' | 'window' | 'when' | 'skip' | 'overlap' | 'lock'): TaskSkipped
|
|
178
|
+
readonly name: string
|
|
179
|
+
readonly reason: 'lock' | 'window' | 'env' | 'when' | 'skip' | 'overlap'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const DEFAULT_RUN_LOG_KEEP = 500
|
|
183
|
+
|
|
184
|
+
const DEFAULT_RUN_LOG_PATH = 'storage/framework/schedule-runs.jsonl'
|
|
185
|
+
|
|
186
|
+
const Scheduler = SchedulerManager
|
|
187
|
+
|
|
188
|
+
const schedulesConcern = ConcernDescriptor
|
|
189
|
+
|
|
190
|
+
function installScheduleRunLog = (app: Application) => (() => void) | undefined
|
|
191
|
+
|
|
192
|
+
function registerSchedule = (manager: SchedulerManager, schedule: Schedule, fallbackName: string) => ScheduledTask | undefined
|
|
193
|
+
|
|
194
|
+
function resolveRunLogConfig = (app: Application) => RunLogConfig
|
|
195
|
+
|
|
196
|
+
function SchedulerConfig = (options?: Partial<SchedulerConfigShape>) => SchedulerConfigShape
|
|
197
|
+
|
|
198
|
+
interface OverlapLockOptions = {
|
|
199
|
+
crossProcess?: boolean
|
|
200
|
+
expiresAfterMinutes?: number
|
|
201
|
+
refresh?: boolean
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface RunLogConfig = {
|
|
205
|
+
enabled: boolean
|
|
206
|
+
keep: number
|
|
207
|
+
path: string
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface SchedulerConfigShape = {
|
|
211
|
+
runLog: { enabled?: boolean; path: string; keep: number;}
|
|
212
|
+
timezone: string
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface ScheduleRunRecord = {
|
|
216
|
+
durationMs: number
|
|
217
|
+
error?: string
|
|
218
|
+
finishedAt: string
|
|
219
|
+
name: string
|
|
220
|
+
ok: boolean
|
|
221
|
+
startedAt: string
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
interface ScheduleRunStore = {
|
|
225
|
+
lastFor: (name: string) => ScheduleRunRecord | undefined
|
|
226
|
+
recent: (limit?: number, name?: string) => ScheduleRunRecord[]
|
|
227
|
+
record: (run: ScheduleRunRecord) => void
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type OutputMailer = (email: string, subject: string, body: string) => void | Promise<void>
|
|
231
|
+
|
|
232
|
+
type TaskCallback = () => void | Promise<void>
|
|
233
|
+
|
|
234
|
+
type TaskGuard = () => boolean | Promise<boolean>
|
|
235
|
+
|
|
236
|
+
type TaskHook = () => void | Promise<void>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerotal/scheduler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"maturity": "stable",
|
|
6
6
|
"private": false,
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"CHANGELOG.md",
|
|
15
|
+
"api-surface.md",
|
|
15
16
|
"src",
|
|
16
17
|
"!src/**/*.test.ts",
|
|
17
18
|
"!src/**/*.test.tsx",
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"typecheck": "tsc --noEmit"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@zerotal/core": "1.
|
|
33
|
+
"@zerotal/core": "1.7.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"typescript": "^5.8.0"
|