exisjs 0.7.6 → 0.7.8
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/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +12 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/clean.d.ts +5 -0
- package/dist/cli/commands/clean.d.ts.map +1 -0
- package/dist/cli/commands/clean.js +30 -0
- package/dist/cli/commands/clean.js.map +1 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +15 -1
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +6 -1
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +57 -2
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/index.js +16 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/manifest.d.ts +1 -0
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +161 -23
- package/dist/cli/manifest.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +9 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/types.d.ts +4 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/cron/expressions.d.ts +45 -0
- package/dist/cron/expressions.d.ts.map +1 -0
- package/dist/cron/expressions.js +87 -0
- package/dist/cron/expressions.js.map +1 -0
- package/dist/cron/index.d.ts +6 -0
- package/dist/cron/index.d.ts.map +1 -0
- package/dist/cron/index.js +22 -0
- package/dist/cron/index.js.map +1 -0
- package/dist/cron/job.d.ts +50 -0
- package/dist/cron/job.d.ts.map +1 -0
- package/dist/cron/job.js +247 -0
- package/dist/cron/job.js.map +1 -0
- package/dist/cron/manager.d.ts +105 -0
- package/dist/cron/manager.d.ts.map +1 -0
- package/dist/cron/manager.js +245 -0
- package/dist/cron/manager.js.map +1 -0
- package/dist/cron/parser.d.ts +22 -0
- package/dist/cron/parser.d.ts.map +1 -0
- package/dist/cron/parser.js +269 -0
- package/dist/cron/parser.js.map +1 -0
- package/dist/cron/types.d.ts +76 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +3 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/decorators/constants.d.ts +2 -0
- package/dist/decorators/constants.d.ts.map +1 -1
- package/dist/decorators/constants.js +3 -1
- package/dist/decorators/constants.js.map +1 -1
- package/dist/decorators/core.d.ts +29 -11
- package/dist/decorators/core.d.ts.map +1 -1
- package/dist/decorators/core.js +49 -11
- package/dist/decorators/core.js.map +1 -1
- package/dist/decorators/cron.d.ts +57 -0
- package/dist/decorators/cron.d.ts.map +1 -0
- package/dist/decorators/cron.js +143 -0
- package/dist/decorators/cron.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/params.d.ts +97 -2
- package/dist/decorators/params.d.ts.map +1 -1
- package/dist/decorators/params.js +94 -2
- package/dist/decorators/params.js.map +1 -1
- package/dist/decorators/routing.d.ts +81 -16
- package/dist/decorators/routing.d.ts.map +1 -1
- package/dist/decorators/routing.js +81 -16
- package/dist/decorators/routing.js.map +1 -1
- package/dist/docs/content/cron.mdx +196 -0
- package/dist/docs/content/errors.mdx +58 -9
- package/dist/docs/content/structure.mdx +1 -1
- package/dist/docs/content/swagger.mdx +289 -0
- package/dist/docs/reference/cron.mdx +300 -0
- package/dist/docs/reference/decorators.mdx +8 -0
- package/dist/docs/reference/error.mdx +44 -0
- package/dist/docs/reference/swagger.mdx +226 -0
- package/dist/docs/reference/validator.mdx +1 -1
- package/dist/router/boundary.d.ts +24 -2
- package/dist/router/boundary.d.ts.map +1 -1
- package/dist/router/boundary.js +24 -2
- package/dist/router/boundary.js.map +1 -1
- package/dist/router/controller-registrar.d.ts.map +1 -1
- package/dist/router/controller-registrar.js +52 -3
- package/dist/router/controller-registrar.js.map +1 -1
- package/dist/router/route-builder.d.ts +196 -33
- package/dist/router/route-builder.d.ts.map +1 -1
- package/dist/router/route-builder.js +171 -11
- package/dist/router/route-builder.js.map +1 -1
- package/dist/router/route-scanner.d.ts +6 -0
- package/dist/router/route-scanner.d.ts.map +1 -1
- package/dist/router/route-scanner.js +69 -812
- package/dist/router/route-scanner.js.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +27 -0
- package/dist/router/router.js.map +1 -1
- package/dist/router/scanner/boundary-loader.d.ts +18 -0
- package/dist/router/scanner/boundary-loader.d.ts.map +1 -0
- package/dist/router/scanner/boundary-loader.js +539 -0
- package/dist/router/scanner/boundary-loader.js.map +1 -0
- package/dist/router/scanner/cron-mounter.d.ts +15 -0
- package/dist/router/scanner/cron-mounter.d.ts.map +1 -0
- package/dist/router/scanner/cron-mounter.js +216 -0
- package/dist/router/scanner/cron-mounter.js.map +1 -0
- package/dist/router/scanner/error-mounter.d.ts +14 -0
- package/dist/router/scanner/error-mounter.d.ts.map +1 -0
- package/dist/router/scanner/error-mounter.js +200 -0
- package/dist/router/scanner/error-mounter.js.map +1 -0
- package/dist/router/scanner/fs-scanner.d.ts +25 -0
- package/dist/router/scanner/fs-scanner.d.ts.map +1 -0
- package/dist/router/scanner/fs-scanner.js +115 -0
- package/dist/router/scanner/fs-scanner.js.map +1 -0
- package/dist/router/scanner/functional-compiler.d.ts +9 -0
- package/dist/router/scanner/functional-compiler.d.ts.map +1 -0
- package/dist/router/scanner/functional-compiler.js +233 -0
- package/dist/router/scanner/functional-compiler.js.map +1 -0
- package/dist/router/scanner/index.d.ts +9 -0
- package/dist/router/scanner/index.d.ts.map +1 -0
- package/dist/router/scanner/index.js +19 -0
- package/dist/router/scanner/index.js.map +1 -0
- package/dist/router/types.d.ts +15 -0
- package/dist/router/types.d.ts.map +1 -1
- package/dist/server/app.d.ts +2 -0
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +3 -0
- package/dist/server/app.js.map +1 -1
- package/dist/server/helpers/body-parser.d.ts +18 -0
- package/dist/server/helpers/body-parser.d.ts.map +1 -0
- package/dist/server/helpers/body-parser.js +246 -0
- package/dist/server/helpers/body-parser.js.map +1 -0
- package/dist/server/helpers/cookie.d.ts +4 -0
- package/dist/server/helpers/cookie.d.ts.map +1 -0
- package/dist/server/helpers/cookie.js +61 -0
- package/dist/server/helpers/cookie.js.map +1 -0
- package/dist/server/helpers/etag.d.ts +3 -0
- package/dist/server/helpers/etag.d.ts.map +1 -0
- package/dist/server/helpers/etag.js +25 -0
- package/dist/server/helpers/etag.js.map +1 -0
- package/dist/server/helpers/index.d.ts +6 -0
- package/dist/server/helpers/index.d.ts.map +1 -0
- package/dist/server/helpers/index.js +21 -0
- package/dist/server/helpers/index.js.map +1 -0
- package/dist/server/helpers/ip.d.ts +9 -0
- package/dist/server/helpers/ip.d.ts.map +1 -0
- package/dist/server/helpers/ip.js +62 -0
- package/dist/server/helpers/ip.js.map +1 -0
- package/dist/server/helpers/stream.d.ts +4 -0
- package/dist/server/helpers/stream.d.ts.map +1 -0
- package/dist/server/helpers/stream.js +193 -0
- package/dist/server/helpers/stream.js.map +1 -0
- package/dist/server/request.d.ts +1 -139
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +19 -433
- package/dist/server/request.js.map +1 -1
- package/dist/server/response.d.ts +105 -158
- package/dist/server/response.d.ts.map +1 -1
- package/dist/server/response.js +121 -423
- package/dist/server/response.js.map +1 -1
- package/dist/swagger/decorators.d.ts +81 -0
- package/dist/swagger/decorators.d.ts.map +1 -0
- package/dist/swagger/decorators.js +172 -0
- package/dist/swagger/decorators.js.map +1 -0
- package/dist/swagger/generator.d.ts +19 -0
- package/dist/swagger/generator.d.ts.map +1 -0
- package/dist/swagger/generator.js +344 -0
- package/dist/swagger/generator.js.map +1 -0
- package/dist/swagger/index.d.ts +31 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +53 -0
- package/dist/swagger/index.js.map +1 -0
- package/dist/swagger/mounter.d.ts +7 -0
- package/dist/swagger/mounter.d.ts.map +1 -0
- package/dist/swagger/mounter.js +56 -0
- package/dist/swagger/mounter.js.map +1 -0
- package/dist/swagger/types.d.ts +190 -0
- package/dist/swagger/types.d.ts.map +1 -0
- package/dist/swagger/types.js +3 -0
- package/dist/swagger/types.js.map +1 -0
- package/dist/swagger/ui.d.ts +6 -0
- package/dist/swagger/ui.d.ts.map +1 -0
- package/dist/swagger/ui.js +118 -0
- package/dist/swagger/ui.js.map +1 -0
- package/dist/validator/builder.d.ts +223 -0
- package/dist/validator/builder.d.ts.map +1 -0
- package/dist/validator/builder.js +517 -0
- package/dist/validator/builder.js.map +1 -0
- package/dist/validator/engine.d.ts +19 -0
- package/dist/validator/engine.d.ts.map +1 -0
- package/dist/validator/engine.js +568 -0
- package/dist/validator/engine.js.map +1 -0
- package/dist/validator/error.d.ts +12 -0
- package/dist/validator/error.d.ts.map +1 -0
- package/dist/validator/error.js +63 -0
- package/dist/validator/error.js.map +1 -0
- package/dist/validator/pagination.d.ts +40 -0
- package/dist/validator/pagination.d.ts.map +1 -0
- package/dist/validator/pagination.js +60 -0
- package/dist/validator/pagination.js.map +1 -0
- package/dist/validator/tex.d.ts +6 -158
- package/dist/validator/tex.d.ts.map +1 -1
- package/dist/validator/tex.js +14 -971
- package/dist/validator/tex.js.map +1 -1
- package/dist/validator/types.d.ts +83 -0
- package/dist/validator/types.d.ts.map +1 -0
- package/dist/validator/types.js +3 -0
- package/dist/validator/types.js.map +1 -0
- package/package.json +9 -1
package/dist/cron/job.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronJob = void 0;
|
|
4
|
+
const parser_1 = require("./parser");
|
|
5
|
+
class CronJob {
|
|
6
|
+
constructor(options, app) {
|
|
7
|
+
this.status = 'idle';
|
|
8
|
+
this.parsedPattern = null;
|
|
9
|
+
this.timer = null;
|
|
10
|
+
this.runningPromise = null;
|
|
11
|
+
this.executionCount = 0;
|
|
12
|
+
this.failureCount = 0;
|
|
13
|
+
this.abortController = null;
|
|
14
|
+
this.app = app;
|
|
15
|
+
this.name =
|
|
16
|
+
options.name || `job_${Math.random().toString(36).substring(2, 9)}`;
|
|
17
|
+
this.schedule = options.schedule;
|
|
18
|
+
this.intervalMs = options.interval;
|
|
19
|
+
this.timeoutMs = options.timeout;
|
|
20
|
+
this.timezone = options.timezone;
|
|
21
|
+
this.preventOverlap = options.preventOverlap !== false;
|
|
22
|
+
this.retries = options.retries ?? 0;
|
|
23
|
+
this.retryDelayMs = options.retryDelayMs ?? 1000;
|
|
24
|
+
this.onErrorHook = options.onError;
|
|
25
|
+
const fn = options.run || options.handle;
|
|
26
|
+
if (typeof fn !== 'function') {
|
|
27
|
+
throw new Error(`CronJob "${this.name}" requires a valid handler function ('run' or 'handle')`);
|
|
28
|
+
}
|
|
29
|
+
this.handler = fn;
|
|
30
|
+
if (this.schedule) {
|
|
31
|
+
this.parsedPattern = (0, parser_1.parseCronExpression)(this.schedule);
|
|
32
|
+
}
|
|
33
|
+
if (options.autoStart !== false) {
|
|
34
|
+
this.start();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getStatus() {
|
|
38
|
+
return this.status;
|
|
39
|
+
}
|
|
40
|
+
getStats() {
|
|
41
|
+
return {
|
|
42
|
+
name: this.name,
|
|
43
|
+
status: this.status,
|
|
44
|
+
schedule: this.schedule,
|
|
45
|
+
intervalMs: this.intervalMs,
|
|
46
|
+
timezone: this.timezone,
|
|
47
|
+
preventOverlap: this.preventOverlap,
|
|
48
|
+
lastRun: this.lastRun,
|
|
49
|
+
nextRun: this.nextRun,
|
|
50
|
+
executionCount: this.executionCount,
|
|
51
|
+
failureCount: this.failureCount,
|
|
52
|
+
lastDurationMs: this.lastDurationMs,
|
|
53
|
+
lastError: this.lastError,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
start() {
|
|
57
|
+
if (this.status === 'running' || this.status === 'idle') {
|
|
58
|
+
this.scheduleNextRun();
|
|
59
|
+
}
|
|
60
|
+
else if (this.status === 'paused' || this.status === 'stopped') {
|
|
61
|
+
this.status = 'idle';
|
|
62
|
+
this.scheduleNextRun();
|
|
63
|
+
}
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
pause() {
|
|
67
|
+
this.status = 'paused';
|
|
68
|
+
if (this.timer) {
|
|
69
|
+
clearTimeout(this.timer);
|
|
70
|
+
this.timer = null;
|
|
71
|
+
}
|
|
72
|
+
this.nextRun = undefined;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
resume() {
|
|
76
|
+
if (this.status === 'paused') {
|
|
77
|
+
this.status = 'idle';
|
|
78
|
+
this.scheduleNextRun();
|
|
79
|
+
}
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
stop() {
|
|
83
|
+
this.status = 'stopped';
|
|
84
|
+
if (this.timer) {
|
|
85
|
+
clearTimeout(this.timer);
|
|
86
|
+
this.timer = null;
|
|
87
|
+
}
|
|
88
|
+
if (this.abortController) {
|
|
89
|
+
this.abortController.abort();
|
|
90
|
+
this.abortController = null;
|
|
91
|
+
}
|
|
92
|
+
this.nextRun = undefined;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Manually triggers an immediate execution of the job without affecting its recurring schedule.
|
|
97
|
+
*/
|
|
98
|
+
async trigger() {
|
|
99
|
+
return this.execute('manual');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Schedules the next timer execution.
|
|
103
|
+
*/
|
|
104
|
+
scheduleNextRun() {
|
|
105
|
+
if (this.status === 'stopped' || this.status === 'paused')
|
|
106
|
+
return;
|
|
107
|
+
if (this.timer) {
|
|
108
|
+
clearTimeout(this.timer);
|
|
109
|
+
this.timer = null;
|
|
110
|
+
}
|
|
111
|
+
if (this.timeoutMs !== undefined) {
|
|
112
|
+
this.nextRun = new Date(Date.now() + this.timeoutMs);
|
|
113
|
+
this.timer = setTimeout(async () => {
|
|
114
|
+
await this.execute('timeout');
|
|
115
|
+
this.status = 'stopped';
|
|
116
|
+
}, this.timeoutMs);
|
|
117
|
+
this.timer.unref?.();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (this.intervalMs !== undefined) {
|
|
121
|
+
this.nextRun = new Date(Date.now() + this.intervalMs);
|
|
122
|
+
this.timer = setTimeout(async () => {
|
|
123
|
+
await this.execute('interval');
|
|
124
|
+
if (this.status !== 'stopped' && this.status !== 'paused') {
|
|
125
|
+
this.scheduleNextRun();
|
|
126
|
+
}
|
|
127
|
+
}, this.intervalMs);
|
|
128
|
+
this.timer.unref?.();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (this.parsedPattern) {
|
|
132
|
+
try {
|
|
133
|
+
const nextDate = (0, parser_1.getNextCronDate)(this.parsedPattern, new Date(), this.timezone);
|
|
134
|
+
this.nextRun = nextDate;
|
|
135
|
+
const delayMs = Math.max(0, nextDate.getTime() - Date.now());
|
|
136
|
+
this.timer = setTimeout(async () => {
|
|
137
|
+
await this.execute('cron');
|
|
138
|
+
if (this.status !== 'stopped' && this.status !== 'paused') {
|
|
139
|
+
this.scheduleNextRun();
|
|
140
|
+
}
|
|
141
|
+
}, delayMs);
|
|
142
|
+
this.timer.unref?.();
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
this.app.log?.error({ err: err.message, job: this.name }, `[exis:cron] Failed to compute next execution date for "${this.name}"`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Executes the handler inside an isolated error sandbox with overlap prevention.
|
|
151
|
+
*/
|
|
152
|
+
async execute(_triggerSource) {
|
|
153
|
+
if (this.status === 'running' && this.preventOverlap) {
|
|
154
|
+
this.app.log?.warn({ job: this.name }, `[exis:cron] Skipped execution of "${this.name}" because previous instance is still running (preventOverlap: true)`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const previousStatus = this.status;
|
|
158
|
+
this.status = 'running';
|
|
159
|
+
this.abortController = new AbortController();
|
|
160
|
+
const startedAt = new Date();
|
|
161
|
+
this.lastRun = startedAt;
|
|
162
|
+
this.executionCount++;
|
|
163
|
+
const context = {
|
|
164
|
+
app: this.app,
|
|
165
|
+
log: this.app.log,
|
|
166
|
+
jobName: this.name,
|
|
167
|
+
startedAt,
|
|
168
|
+
iteration: this.executionCount,
|
|
169
|
+
signal: this.abortController.signal,
|
|
170
|
+
};
|
|
171
|
+
const startTimer = process.hrtime();
|
|
172
|
+
const runWithRetry = async (attempt = 0) => {
|
|
173
|
+
try {
|
|
174
|
+
return await this.handler(context);
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
if (attempt < this.retries) {
|
|
178
|
+
this.app.log?.warn({ job: this.name, attempt: attempt + 1, retries: this.retries }, `[exis:cron] Retrying job "${this.name}" in ${this.retryDelayMs}ms`);
|
|
179
|
+
await new Promise((resolve) => setTimeout(resolve, this.retryDelayMs));
|
|
180
|
+
return runWithRetry(attempt + 1);
|
|
181
|
+
}
|
|
182
|
+
throw err;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
this.runningPromise = runWithRetry();
|
|
186
|
+
try {
|
|
187
|
+
const result = await this.runningPromise;
|
|
188
|
+
const [sec, nano] = process.hrtime(startTimer);
|
|
189
|
+
this.lastDurationMs = Math.round(sec * 1000 + nano / 1e6);
|
|
190
|
+
this.lastError = undefined;
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
const [sec, nano] = process.hrtime(startTimer);
|
|
195
|
+
this.lastDurationMs = Math.round(sec * 1000 + nano / 1e6);
|
|
196
|
+
this.failureCount++;
|
|
197
|
+
this.lastError = err?.message || String(err);
|
|
198
|
+
this.app.log?.error({
|
|
199
|
+
err: this.lastError,
|
|
200
|
+
job: this.name,
|
|
201
|
+
durationMs: this.lastDurationMs,
|
|
202
|
+
}, `[exis:cron] Unhandled error in cron job "${this.name}"`);
|
|
203
|
+
if (this.onErrorHook) {
|
|
204
|
+
try {
|
|
205
|
+
await this.onErrorHook(err, context);
|
|
206
|
+
}
|
|
207
|
+
catch (hookErr) {
|
|
208
|
+
this.app.log?.error({ err: hookErr.message, job: this.name }, `[exis:cron] Error in onError hook for "${this.name}"`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
this.runningPromise = null;
|
|
214
|
+
this.abortController = null;
|
|
215
|
+
if (this.status === 'running') {
|
|
216
|
+
this.status = previousStatus === 'running' ? 'idle' : previousStatus;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Awaits completion of in-flight execution during graceful shutdown.
|
|
222
|
+
*/
|
|
223
|
+
async drain(timeoutMs = 5000) {
|
|
224
|
+
this.stop();
|
|
225
|
+
if (this.runningPromise) {
|
|
226
|
+
let timeoutHandle;
|
|
227
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
228
|
+
timeoutHandle = setTimeout(() => {
|
|
229
|
+
reject(new Error(`[exis:cron] Job "${this.name}" drain timed out after ${timeoutMs}ms`));
|
|
230
|
+
}, timeoutMs);
|
|
231
|
+
timeoutHandle.unref?.();
|
|
232
|
+
});
|
|
233
|
+
try {
|
|
234
|
+
await Promise.race([this.runningPromise, timeoutPromise]);
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
this.app.log?.warn({ err }, `[exis:cron] Drain timeout on job "${this.name}"`);
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
if (timeoutHandle)
|
|
241
|
+
clearTimeout(timeoutHandle);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.CronJob = CronJob;
|
|
247
|
+
//# sourceMappingURL=job.js.map
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@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { App } from '../server/app';
|
|
2
|
+
import { CronJob } from './job';
|
|
3
|
+
import type { CronJobOptions, CronJobStats, CronContext } from './types';
|
|
4
|
+
export declare class CronManager {
|
|
5
|
+
private jobs;
|
|
6
|
+
private app;
|
|
7
|
+
constructor(app: App<any>);
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether a cron job with the given name is registered.
|
|
10
|
+
*/
|
|
11
|
+
has(name: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Registers and optionally starts a scheduled background task or cron job.
|
|
14
|
+
*
|
|
15
|
+
* @param nameOrOptions Job name or configuration options
|
|
16
|
+
* @param schedule Optional cron schedule pattern if name is passed as first argument
|
|
17
|
+
* @param handler Optional execution handler if name is passed as first argument
|
|
18
|
+
* @param options Optional additional configuration options
|
|
19
|
+
* @returns Active `CronJob` instance
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* app.cron.schedule({
|
|
24
|
+
* name: 'nightly-backup',
|
|
25
|
+
* schedule: '0 2 * * *',
|
|
26
|
+
* timezone: 'UTC',
|
|
27
|
+
* run: async ({ log }) => {
|
|
28
|
+
* log.info('Running database backup')
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
schedule(nameOrOptions: string | CronJobOptions, schedule?: string, handler?: (ctx: CronContext) => any, options?: Partial<CronJobOptions>): CronJob;
|
|
34
|
+
/**
|
|
35
|
+
* Schedules a recurring task using fixed millisecond intervals.
|
|
36
|
+
*/
|
|
37
|
+
interval(name: string, ms: number, handler: (ctx: CronContext) => any, options?: Partial<CronJobOptions>): CronJob;
|
|
38
|
+
/**
|
|
39
|
+
* Schedules a one-time delayed task.
|
|
40
|
+
*/
|
|
41
|
+
timeout(name: string, ms: number, handler: (ctx: CronContext) => any, options?: Partial<CronJobOptions>): CronJob;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves a registered cron job by its unique identifier.
|
|
44
|
+
*/
|
|
45
|
+
getJob(name: string): CronJob | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a snapshot map of all registered cron jobs and their execution statistics.
|
|
48
|
+
*/
|
|
49
|
+
getJobs(): Map<string, CronJob>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns an array of statistics for all registered jobs (last run, failure count, execution duration).
|
|
52
|
+
*/
|
|
53
|
+
getStats(): CronJobStats[];
|
|
54
|
+
/**
|
|
55
|
+
* Starts all registered idle, paused, or stopped cron jobs.
|
|
56
|
+
*/
|
|
57
|
+
startAll(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Pauses all registered active cron jobs.
|
|
60
|
+
*/
|
|
61
|
+
pauseAll(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Permanently stops all registered cron jobs.
|
|
64
|
+
*/
|
|
65
|
+
stopAll(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Triggers immediate manual execution of a specific cron job by name.
|
|
68
|
+
*/
|
|
69
|
+
trigger(name: string): Promise<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Gracefully waits for all in-flight cron job executions to finish before server shutdown.
|
|
72
|
+
*/
|
|
73
|
+
drain(timeoutMs?: number): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Functional definition helper object for ExisJS cron jobs.
|
|
77
|
+
*/
|
|
78
|
+
export interface FunctionalCronDefinition {
|
|
79
|
+
__isExisCron: true;
|
|
80
|
+
options: CronJobOptions;
|
|
81
|
+
handler?: (ctx: CronContext) => any;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Declarative helper for creating scheduled background jobs and cron tasks.
|
|
85
|
+
*
|
|
86
|
+
* @param scheduleOrOptions Standard 5/6-field cron pattern (e.g. `'0 * * * *'`) or full `CronJobOptions`
|
|
87
|
+
* @param handler Execution function receiving `CronContext`
|
|
88
|
+
* @returns Functional cron definition ready for export
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* // src/cron/cleanup.ts
|
|
93
|
+
* export default cron('0 0 * * *', async ({ log }) => {
|
|
94
|
+
* log.info('Running nightly cleanup')
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function cron(scheduleOrOptions: string | CronJobOptions, handler?: (ctx: CronContext) => any): FunctionalCronDefinition;
|
|
99
|
+
export declare namespace cron {
|
|
100
|
+
var every: (duration: string, handler: (ctx: CronContext) => any, options?: Omit<CronJobOptions, "schedule" | "run" | "handle">) => FunctionalCronDefinition;
|
|
101
|
+
var interval: (ms: number, handler: (ctx: CronContext) => any, options?: Omit<CronJobOptions, "interval" | "run" | "handle">) => FunctionalCronDefinition;
|
|
102
|
+
var timeout: (ms: number, handler: (ctx: CronContext) => any, options?: Omit<CronJobOptions, "timeout" | "run" | "handle">) => FunctionalCronDefinition;
|
|
103
|
+
}
|
|
104
|
+
export declare const defineCron: typeof cron;
|
|
105
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/cron/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAGxE,qBAAa,WAAW;IACtB,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,GAAG,CAAU;gBAET,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IAIzB;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,QAAQ,CACb,aAAa,EAAE,MAAM,GAAG,cAAc,EACtC,QAAQ,CAAC,EAAE,MAAM,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GAAG,EAAE,WAAW,KAAK,GAAG,GAClC,wBAAwB,CAoB1B;yBAvBe,IAAI;0BAyCR,MAAM,WACP,CAAC,GAAG,EAAE,WAAW,KAAK,GAAG,YACzB,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC,KAC3D,wBAAwB;uBAwBrB,MAAM,WACD,CAAC,GAAG,EAAE,WAAW,KAAK,GAAG,YACzB,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC,KAC3D,wBAAwB;sBAwBrB,MAAM,WACD,CAAC,GAAG,EAAE,WAAW,KAAK,GAAG,YACzB,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC,KAC1D,wBAAwB;;AAQ3B,eAAO,MAAM,UAAU,aAAO,CAAA"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineCron = exports.CronManager = void 0;
|
|
4
|
+
exports.cron = cron;
|
|
5
|
+
const job_1 = require("./job");
|
|
6
|
+
const expressions_1 = require("./expressions");
|
|
7
|
+
class CronManager {
|
|
8
|
+
constructor(app) {
|
|
9
|
+
this.jobs = new Map();
|
|
10
|
+
this.app = app;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether a cron job with the given name is registered.
|
|
14
|
+
*/
|
|
15
|
+
has(name) {
|
|
16
|
+
return this.jobs.has(name);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Registers and optionally starts a scheduled background task or cron job.
|
|
20
|
+
*
|
|
21
|
+
* @param nameOrOptions Job name or configuration options
|
|
22
|
+
* @param schedule Optional cron schedule pattern if name is passed as first argument
|
|
23
|
+
* @param handler Optional execution handler if name is passed as first argument
|
|
24
|
+
* @param options Optional additional configuration options
|
|
25
|
+
* @returns Active `CronJob` instance
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* app.cron.schedule({
|
|
30
|
+
* name: 'nightly-backup',
|
|
31
|
+
* schedule: '0 2 * * *',
|
|
32
|
+
* timezone: 'UTC',
|
|
33
|
+
* run: async ({ log }) => {
|
|
34
|
+
* log.info('Running database backup')
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
schedule(nameOrOptions, schedule, handler, options) {
|
|
40
|
+
let opts;
|
|
41
|
+
if (typeof nameOrOptions === 'string') {
|
|
42
|
+
opts = {
|
|
43
|
+
name: nameOrOptions,
|
|
44
|
+
schedule: schedule,
|
|
45
|
+
run: handler,
|
|
46
|
+
...options,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
opts = nameOrOptions;
|
|
51
|
+
}
|
|
52
|
+
const job = new job_1.CronJob(opts, this.app);
|
|
53
|
+
if (this.jobs.has(job.name)) {
|
|
54
|
+
this.app.log?.warn({ job: job.name }, `[exis:cron] Overwriting existing cron job "${job.name}"`);
|
|
55
|
+
this.jobs.get(job.name)?.stop();
|
|
56
|
+
}
|
|
57
|
+
this.jobs.set(job.name, job);
|
|
58
|
+
return job;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Schedules a recurring task using fixed millisecond intervals.
|
|
62
|
+
*/
|
|
63
|
+
interval(name, ms, handler, options) {
|
|
64
|
+
return this.schedule({
|
|
65
|
+
name,
|
|
66
|
+
interval: ms,
|
|
67
|
+
run: handler,
|
|
68
|
+
...options,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Schedules a one-time delayed task.
|
|
73
|
+
*/
|
|
74
|
+
timeout(name, ms, handler, options) {
|
|
75
|
+
return this.schedule({
|
|
76
|
+
name,
|
|
77
|
+
timeout: ms,
|
|
78
|
+
run: handler,
|
|
79
|
+
...options,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves a registered cron job by its unique identifier.
|
|
84
|
+
*/
|
|
85
|
+
getJob(name) {
|
|
86
|
+
return this.jobs.get(name);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns a snapshot map of all registered cron jobs and their execution statistics.
|
|
90
|
+
*/
|
|
91
|
+
getJobs() {
|
|
92
|
+
return this.jobs;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns an array of statistics for all registered jobs (last run, failure count, execution duration).
|
|
96
|
+
*/
|
|
97
|
+
getStats() {
|
|
98
|
+
return Array.from(this.jobs.values()).map((job) => job.getStats());
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Starts all registered idle, paused, or stopped cron jobs.
|
|
102
|
+
*/
|
|
103
|
+
startAll() {
|
|
104
|
+
for (const job of this.jobs.values()) {
|
|
105
|
+
job.start();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Pauses all registered active cron jobs.
|
|
110
|
+
*/
|
|
111
|
+
pauseAll() {
|
|
112
|
+
for (const job of this.jobs.values()) {
|
|
113
|
+
job.pause();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Permanently stops all registered cron jobs.
|
|
118
|
+
*/
|
|
119
|
+
stopAll() {
|
|
120
|
+
for (const job of this.jobs.values()) {
|
|
121
|
+
job.stop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Triggers immediate manual execution of a specific cron job by name.
|
|
126
|
+
*/
|
|
127
|
+
async trigger(name) {
|
|
128
|
+
const job = this.jobs.get(name);
|
|
129
|
+
if (!job) {
|
|
130
|
+
throw new Error(`[exis:cron] Job "${name}" not found`);
|
|
131
|
+
}
|
|
132
|
+
return job.trigger();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gracefully waits for all in-flight cron job executions to finish before server shutdown.
|
|
136
|
+
*/
|
|
137
|
+
async drain(timeoutMs = 5000) {
|
|
138
|
+
const drainPromises = Array.from(this.jobs.values()).map((job) => job.drain(timeoutMs));
|
|
139
|
+
await Promise.all(drainPromises);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.CronManager = CronManager;
|
|
143
|
+
/**
|
|
144
|
+
* Declarative helper for creating scheduled background jobs and cron tasks.
|
|
145
|
+
*
|
|
146
|
+
* @param scheduleOrOptions Standard 5/6-field cron pattern (e.g. `'0 * * * *'`) or full `CronJobOptions`
|
|
147
|
+
* @param handler Execution function receiving `CronContext`
|
|
148
|
+
* @returns Functional cron definition ready for export
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* // src/cron/cleanup.ts
|
|
153
|
+
* export default cron('0 0 * * *', async ({ log }) => {
|
|
154
|
+
* log.info('Running nightly cleanup')
|
|
155
|
+
* })
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
function cron(scheduleOrOptions, handler) {
|
|
159
|
+
let options;
|
|
160
|
+
if (typeof scheduleOrOptions === 'string') {
|
|
161
|
+
options = {
|
|
162
|
+
schedule: scheduleOrOptions,
|
|
163
|
+
run: handler,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
options = {
|
|
168
|
+
...scheduleOrOptions,
|
|
169
|
+
run: handler || scheduleOrOptions.run || scheduleOrOptions.handle,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
__isExisCron: true,
|
|
174
|
+
options,
|
|
175
|
+
handler: options.run,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Schedules a cron job with human-readable English duration expressions.
|
|
180
|
+
*
|
|
181
|
+
* @param duration Natural language interval (e.g. `'5 minutes'`, `'1 hour'`, `'30 seconds'`, `'every weekday'`)
|
|
182
|
+
* @param handler Execution function receiving `CronContext`
|
|
183
|
+
* @param options Additional job options (retries, timezone, onError)
|
|
184
|
+
* @returns Functional cron definition
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* export default cron.every('15 minutes', async ({ log }) => {
|
|
189
|
+
* log.info('Heartbeat check')
|
|
190
|
+
* })
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
cron.every = function (duration, handler, options = {}) {
|
|
194
|
+
return cron({
|
|
195
|
+
schedule: (0, expressions_1.every)(duration),
|
|
196
|
+
run: handler,
|
|
197
|
+
...options,
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Schedules a background task using millisecond fixed intervals with drift correction.
|
|
202
|
+
*
|
|
203
|
+
* @param ms Millisecond interval between executions
|
|
204
|
+
* @param handler Execution function receiving `CronContext`
|
|
205
|
+
* @param options Additional job options (retries, preventOverlap)
|
|
206
|
+
* @returns Functional cron definition
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* export default cron.interval(60000, async ({ log }) => {
|
|
211
|
+
* log.info('Running every 60 seconds')
|
|
212
|
+
* })
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
cron.interval = function (ms, handler, options = {}) {
|
|
216
|
+
return cron({
|
|
217
|
+
interval: ms,
|
|
218
|
+
run: handler,
|
|
219
|
+
...options,
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Schedules a one-time background task to execute after a specified delay.
|
|
224
|
+
*
|
|
225
|
+
* @param ms Delay in milliseconds before execution
|
|
226
|
+
* @param handler Execution function receiving `CronContext`
|
|
227
|
+
* @param options Additional job options
|
|
228
|
+
* @returns Functional cron definition
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* export default cron.timeout(5000, async ({ log }) => {
|
|
233
|
+
* log.info('Executed once after 5s startup delay')
|
|
234
|
+
* })
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
cron.timeout = function (ms, handler, options = {}) {
|
|
238
|
+
return cron({
|
|
239
|
+
timeout: ms,
|
|
240
|
+
run: handler,
|
|
241
|
+
...options,
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
exports.defineCron = cron;
|
|
245
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/cron/manager.ts"],"names":[],"mappings":";;;AAuMA,oBAuBC;AA7ND,+BAA+B;AAE/B,+CAAqC;AAErC,MAAa,WAAW;IAItB,YAAY,GAAa;QAHjB,SAAI,GAAG,IAAI,GAAG,EAAmB,CAAA;QAIvC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,QAAQ,CACb,aAAsC,EACtC,QAAiB,EACjB,OAAmC,EACnC,OAAiC;QAEjC,IAAI,IAAoB,CAAA;QACxB,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;YACtC,IAAI,GAAG;gBACL,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE,QAAS;gBACnB,GAAG,EAAE,OAAQ;gBACb,GAAG,OAAO;aACX,CAAA;QACH,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,aAAa,CAAA;QACtB,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,aAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;QACvC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAChB,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EACjB,8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,GAAG,iBAAiB;YACpB,GAAG,EAAE,OAAO,IAAI,iBAAiB,CAAC,GAAG,IAAI,iBAAiB,CAAC,MAAM;SAClE,CAAA;IACH,CAAC;IAED,OAAO;QACL,YAAY,EAAE,IAAI;QAClB,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,GAAG;KACrB,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,IAAI,CAAC,KAAK,GAAG,UACX,QAAgB,EAChB,OAAkC,EAClC,UAA+D,EAAE;IAEjE,OAAO,IAAI,CAAC;QACV,QAAQ,EAAE,IAAA,mBAAK,EAAC,QAAQ,CAAC;QACzB,GAAG,EAAE,OAAO;QACZ,GAAG,OAAO;KACX,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,IAAI,CAAC,QAAQ,GAAG,UACd,EAAU,EACV,OAAkC,EAClC,UAA+D,EAAE;IAEjE,OAAO,IAAI,CAAC;QACV,QAAQ,EAAE,EAAE;QACZ,GAAG,EAAE,OAAO;QACZ,GAAG,OAAO;KACX,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,IAAI,CAAC,OAAO,GAAG,UACb,EAAU,EACV,OAAkC,EAClC,UAA8D,EAAE;IAEhE,OAAO,IAAI,CAAC;QACV,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,OAAO;QACZ,GAAG,OAAO;KACX,CAAC,CAAA;AACJ,CAAC,CAAA;AAEY,QAAA,UAAU,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ParsedCronPattern {
|
|
2
|
+
hasSeconds: boolean;
|
|
3
|
+
seconds: Set<number>;
|
|
4
|
+
minutes: Set<number>;
|
|
5
|
+
hours: Set<number>;
|
|
6
|
+
daysOfMonth: Set<number>;
|
|
7
|
+
months: Set<number>;
|
|
8
|
+
daysOfWeek: Set<number>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parses a 5 or 6 field cron expression into a structured pattern object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseCronExpression(expression: string): ParsedCronPattern;
|
|
14
|
+
/**
|
|
15
|
+
* Validates whether a cron expression is syntactically valid.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isValidCron(expression: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the next occurrence Date for a cron pattern from a base date.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getNextCronDate(pattern: ParsedCronPattern | string, fromDate?: Date, timezone?: string): Date;
|
|
22
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/cron/parser.ts"],"names":[],"mappings":"AAmCA,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACnB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACxB;AA8ED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAkCzE;AAkFD;;GAEG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAOvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,iBAAiB,GAAG,MAAM,EACnC,QAAQ,OAAa,EACrB,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CAwDN"}
|