@warlock.js/scheduler 5.24.0 → 5.25.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/CHANGELOG.md +6 -0
- package/cjs/index.cjs +49 -3
- package/cjs/index.cjs.map +1 -1
- package/esm/process-roles.mjs +37 -0
- package/esm/process-roles.mjs.map +1 -0
- package/esm/scheduler.d.mts +9 -2
- package/esm/scheduler.d.mts.map +1 -1
- package/esm/scheduler.mjs +15 -3
- package/esm/scheduler.mjs.map +1 -1
- package/llms-full.txt +683 -683
- package/package.json +2 -2
- package/skills/configure-retry-and-overlap/SKILL.md +152 -152
- package/skills/observe-scheduler/SKILL.md +153 -153
- package/skills/pin-schedule-timezone/SKILL.md +114 -114
- package/skills/schedule-fluently/SKILL.md +141 -141
- package/skills/schedule-with-cron/SKILL.md +123 -123
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: schedule-with-cron
|
|
3
|
-
description: 'Write `.cron(''…'')` expressions — 5-field syntax, operators (`*` `,` `-` `/`), Vixie OR semantics for DOM / DOW, `parseCron()` preview utility. Triggers: `.cron`, `parseCron`, `CronParser`, `*/5 * * * *`, `0 9 * * 1-5`; "write a cron expression", "every weekday at 9am cron", "preview next cron run", "migrate crontab(5) entry"; typical import `import { parseCron } from "@warlock.js/scheduler"`. Skip: human-readable schedules — `@warlock.js/scheduler/schedule-fluently/SKILL.md`; timezone — `@warlock.js/scheduler/pin-schedule-timezone/SKILL.md`; competing libs `node-cron`, `cron`, `croner`, `cronstrue`.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Cron expressions
|
|
7
|
-
|
|
8
|
-
The escape hatch when the fluent API can't express a schedule. Activating `.cron()` clears any prior fluent config — the two are mutually exclusive.
|
|
9
|
-
|
|
10
|
-
## 5-field syntax
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
┌───────────── minute (0-59)
|
|
14
|
-
│ ┌───────────── hour (0-23)
|
|
15
|
-
│ │ ┌───────────── day-of-month (1-31)
|
|
16
|
-
│ │ │ ┌───────────── month (1-12)
|
|
17
|
-
│ │ │ │ ┌───────────── day-of-week (0-6, Sunday = 0)
|
|
18
|
-
│ │ │ │ │
|
|
19
|
-
* * * * *
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**Note:** Sunday is `0` only. Some cron dialects also accept `7` for Sunday — this parser does NOT.
|
|
23
|
-
|
|
24
|
-
## Operators
|
|
25
|
-
|
|
26
|
-
| Syntax | Meaning | Example |
|
|
27
|
-
| --------- | ----------------------------- | ---------------- |
|
|
28
|
-
| `*` | Any value (full range) | `* * * * *` |
|
|
29
|
-
| `5` | Single value | `30 14 * * *` |
|
|
30
|
-
| `1,3,5` | List | `0,30 * * * *` |
|
|
31
|
-
| `1-5` | Inclusive range | `0 9-17 * * *` |
|
|
32
|
-
| `*/N` | Step over the wildcard | `*/5 * * * *` |
|
|
33
|
-
| `A-B/N` | Step over a range | `0 1-10/2 * * *` |
|
|
34
|
-
|
|
35
|
-
**Not supported (yet):** named tokens (`MON-FRI`, `JAN-DEC`), special strings (`@daily`, `@hourly`, `@reboot`), seconds field (6-field), Quartz modifiers (`L`, `W`, `#`).
|
|
36
|
-
|
|
37
|
-
## Day-of-month + day-of-week — Vixie OR semantics
|
|
38
|
-
|
|
39
|
-
When **both** `dayOfMonth` AND `dayOfWeek` are restricted (neither is `*`), the date matches if **either** constraint matches. When one is `*` and the other is restricted, only the restricted one matters.
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
// "1st of month OR any Monday" — fires on the 1st even if not a Monday,
|
|
43
|
-
// AND fires on any Monday even if not the 1st.
|
|
44
|
-
job("digest", sendDigest).cron("0 0 1 * 1");
|
|
45
|
-
|
|
46
|
-
// "15th of month" — DOW is *, so only DOM applies. Fires only on the 15th.
|
|
47
|
-
job("midmonth", task).cron("0 0 15 * *");
|
|
48
|
-
|
|
49
|
-
// "Every Monday" — DOM is *, so only DOW applies. Fires only on Mondays.
|
|
50
|
-
job("monday-only", task).cron("0 0 * * 1");
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
This matches Vixie cron (the de facto standard on Unix). Migrating an existing cron table from `crontab(5)` should "just work" semantically.
|
|
54
|
-
|
|
55
|
-
## Common recipes
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
// Every 5 minutes
|
|
59
|
-
.cron("*/5 * * * *")
|
|
60
|
-
|
|
61
|
-
// Top of every hour
|
|
62
|
-
.cron("0 * * * *")
|
|
63
|
-
|
|
64
|
-
// Every weekday at 9 AM
|
|
65
|
-
.cron("0 9 * * 1-5")
|
|
66
|
-
|
|
67
|
-
// 2:30 PM on the 15th of every month
|
|
68
|
-
.cron("30 14 15 * *")
|
|
69
|
-
|
|
70
|
-
// Every 2 hours, on the hour
|
|
71
|
-
.cron("0 */2 * * *")
|
|
72
|
-
|
|
73
|
-
// First day of each month at midnight
|
|
74
|
-
.cron("0 0 1 * *")
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Validation
|
|
78
|
-
|
|
79
|
-
`new CronParser(expr)` and `.cron(expr)` both throw at definition time on:
|
|
80
|
-
|
|
81
|
-
- Wrong field count (must be exactly 5)
|
|
82
|
-
- Non-numeric values, out-of-range values, inverted ranges (`5-1`)
|
|
83
|
-
- Step `<= 0`, non-numeric step
|
|
84
|
-
- Impossible day-of-month / month combinations — a date that can never occur, e.g. `0 0 30 2 *` (Feb 30) or `0 0 31 4 *` (April has 30 days). Rejected with an `Impossible cron expression` error.
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
new CronParser("0 0 30 2 *"); // throws: Impossible cron expression — Feb never has a 30th
|
|
88
|
-
new CronParser("0 0 31 4 *"); // throws: April has only 30 days
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
**Leap years and the OR escape hatch.** `0 0 29 2 *` (Feb 29) is **accepted** — it occurs in leap years. And when day-of-week is also restricted, Vixie OR semantics keep the schedule alive via the weekday path, so the combo is never rejected: `0 0 30 2 1` (Feb 30 OR any Monday) parses fine and fires on Mondays.
|
|
92
|
-
|
|
93
|
-
Throws are eager — bad expressions fail fast at construction, not at first tick.
|
|
94
|
-
|
|
95
|
-
## Standalone preview — `parseCron()`
|
|
96
|
-
|
|
97
|
-
The `CronParser` class is exported as a utility for ad-hoc next-run calculation, separate from any job:
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import { parseCron } from "@warlock.js/scheduler";
|
|
101
|
-
import dayjs from "dayjs";
|
|
102
|
-
|
|
103
|
-
const parser = parseCron("0 9 * * 1-5");
|
|
104
|
-
|
|
105
|
-
parser.nextRun().toISOString(); // next weekday at 9 AM
|
|
106
|
-
parser.nextRun(dayjs("2026-12-31")).format(); // from a specific anchor
|
|
107
|
-
|
|
108
|
-
parser.matches(dayjs()); // is "now" a fire moment?
|
|
109
|
-
|
|
110
|
-
parser.fields; // parsed numeric arrays
|
|
111
|
-
parser.expression; // original string
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Impossible expressions are rejected eagerly at construction (see Validation), so `nextRun(from?)` always resolves a satisfiable expression within a year — its one-year scan bound is just a defensive backstop, never the path that catches a bad expression.
|
|
115
|
-
|
|
116
|
-
## Timezone interaction
|
|
117
|
-
|
|
118
|
-
If the job has `.inTimezone(tz)`, the cron parser receives a timezone-aware `dayjs` object — so `0 9 * * *` with `.inTimezone("Asia/Tokyo")` fires at 09:00 JST. See [`@warlock.js/scheduler/pin-schedule-timezone/SKILL.md`](@warlock.js/scheduler/pin-schedule-timezone/SKILL.md).
|
|
119
|
-
|
|
120
|
-
## See also
|
|
121
|
-
|
|
122
|
-
- [`@warlock.js/scheduler/schedule-fluently/SKILL.md`](@warlock.js/scheduler/schedule-fluently/SKILL.md) — the higher-level alternative for human-readable schedules
|
|
123
|
-
- [`@warlock.js/scheduler/pin-schedule-timezone/SKILL.md`](@warlock.js/scheduler/pin-schedule-timezone/SKILL.md) — pinning a cron schedule to a wall-clock timezone
|
|
1
|
+
---
|
|
2
|
+
name: schedule-with-cron
|
|
3
|
+
description: 'Write `.cron(''…'')` expressions — 5-field syntax, operators (`*` `,` `-` `/`), Vixie OR semantics for DOM / DOW, `parseCron()` preview utility. Triggers: `.cron`, `parseCron`, `CronParser`, `*/5 * * * *`, `0 9 * * 1-5`; "write a cron expression", "every weekday at 9am cron", "preview next cron run", "migrate crontab(5) entry"; typical import `import { parseCron } from "@warlock.js/scheduler"`. Skip: human-readable schedules — `@warlock.js/scheduler/schedule-fluently/SKILL.md`; timezone — `@warlock.js/scheduler/pin-schedule-timezone/SKILL.md`; competing libs `node-cron`, `cron`, `croner`, `cronstrue`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cron expressions
|
|
7
|
+
|
|
8
|
+
The escape hatch when the fluent API can't express a schedule. Activating `.cron()` clears any prior fluent config — the two are mutually exclusive.
|
|
9
|
+
|
|
10
|
+
## 5-field syntax
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
┌───────────── minute (0-59)
|
|
14
|
+
│ ┌───────────── hour (0-23)
|
|
15
|
+
│ │ ┌───────────── day-of-month (1-31)
|
|
16
|
+
│ │ │ ┌───────────── month (1-12)
|
|
17
|
+
│ │ │ │ ┌───────────── day-of-week (0-6, Sunday = 0)
|
|
18
|
+
│ │ │ │ │
|
|
19
|
+
* * * * *
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Note:** Sunday is `0` only. Some cron dialects also accept `7` for Sunday — this parser does NOT.
|
|
23
|
+
|
|
24
|
+
## Operators
|
|
25
|
+
|
|
26
|
+
| Syntax | Meaning | Example |
|
|
27
|
+
| --------- | ----------------------------- | ---------------- |
|
|
28
|
+
| `*` | Any value (full range) | `* * * * *` |
|
|
29
|
+
| `5` | Single value | `30 14 * * *` |
|
|
30
|
+
| `1,3,5` | List | `0,30 * * * *` |
|
|
31
|
+
| `1-5` | Inclusive range | `0 9-17 * * *` |
|
|
32
|
+
| `*/N` | Step over the wildcard | `*/5 * * * *` |
|
|
33
|
+
| `A-B/N` | Step over a range | `0 1-10/2 * * *` |
|
|
34
|
+
|
|
35
|
+
**Not supported (yet):** named tokens (`MON-FRI`, `JAN-DEC`), special strings (`@daily`, `@hourly`, `@reboot`), seconds field (6-field), Quartz modifiers (`L`, `W`, `#`).
|
|
36
|
+
|
|
37
|
+
## Day-of-month + day-of-week — Vixie OR semantics
|
|
38
|
+
|
|
39
|
+
When **both** `dayOfMonth` AND `dayOfWeek` are restricted (neither is `*`), the date matches if **either** constraint matches. When one is `*` and the other is restricted, only the restricted one matters.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// "1st of month OR any Monday" — fires on the 1st even if not a Monday,
|
|
43
|
+
// AND fires on any Monday even if not the 1st.
|
|
44
|
+
job("digest", sendDigest).cron("0 0 1 * 1");
|
|
45
|
+
|
|
46
|
+
// "15th of month" — DOW is *, so only DOM applies. Fires only on the 15th.
|
|
47
|
+
job("midmonth", task).cron("0 0 15 * *");
|
|
48
|
+
|
|
49
|
+
// "Every Monday" — DOM is *, so only DOW applies. Fires only on Mondays.
|
|
50
|
+
job("monday-only", task).cron("0 0 * * 1");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This matches Vixie cron (the de facto standard on Unix). Migrating an existing cron table from `crontab(5)` should "just work" semantically.
|
|
54
|
+
|
|
55
|
+
## Common recipes
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// Every 5 minutes
|
|
59
|
+
.cron("*/5 * * * *")
|
|
60
|
+
|
|
61
|
+
// Top of every hour
|
|
62
|
+
.cron("0 * * * *")
|
|
63
|
+
|
|
64
|
+
// Every weekday at 9 AM
|
|
65
|
+
.cron("0 9 * * 1-5")
|
|
66
|
+
|
|
67
|
+
// 2:30 PM on the 15th of every month
|
|
68
|
+
.cron("30 14 15 * *")
|
|
69
|
+
|
|
70
|
+
// Every 2 hours, on the hour
|
|
71
|
+
.cron("0 */2 * * *")
|
|
72
|
+
|
|
73
|
+
// First day of each month at midnight
|
|
74
|
+
.cron("0 0 1 * *")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Validation
|
|
78
|
+
|
|
79
|
+
`new CronParser(expr)` and `.cron(expr)` both throw at definition time on:
|
|
80
|
+
|
|
81
|
+
- Wrong field count (must be exactly 5)
|
|
82
|
+
- Non-numeric values, out-of-range values, inverted ranges (`5-1`)
|
|
83
|
+
- Step `<= 0`, non-numeric step
|
|
84
|
+
- Impossible day-of-month / month combinations — a date that can never occur, e.g. `0 0 30 2 *` (Feb 30) or `0 0 31 4 *` (April has 30 days). Rejected with an `Impossible cron expression` error.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
new CronParser("0 0 30 2 *"); // throws: Impossible cron expression — Feb never has a 30th
|
|
88
|
+
new CronParser("0 0 31 4 *"); // throws: April has only 30 days
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Leap years and the OR escape hatch.** `0 0 29 2 *` (Feb 29) is **accepted** — it occurs in leap years. And when day-of-week is also restricted, Vixie OR semantics keep the schedule alive via the weekday path, so the combo is never rejected: `0 0 30 2 1` (Feb 30 OR any Monday) parses fine and fires on Mondays.
|
|
92
|
+
|
|
93
|
+
Throws are eager — bad expressions fail fast at construction, not at first tick.
|
|
94
|
+
|
|
95
|
+
## Standalone preview — `parseCron()`
|
|
96
|
+
|
|
97
|
+
The `CronParser` class is exported as a utility for ad-hoc next-run calculation, separate from any job:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { parseCron } from "@warlock.js/scheduler";
|
|
101
|
+
import dayjs from "dayjs";
|
|
102
|
+
|
|
103
|
+
const parser = parseCron("0 9 * * 1-5");
|
|
104
|
+
|
|
105
|
+
parser.nextRun().toISOString(); // next weekday at 9 AM
|
|
106
|
+
parser.nextRun(dayjs("2026-12-31")).format(); // from a specific anchor
|
|
107
|
+
|
|
108
|
+
parser.matches(dayjs()); // is "now" a fire moment?
|
|
109
|
+
|
|
110
|
+
parser.fields; // parsed numeric arrays
|
|
111
|
+
parser.expression; // original string
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Impossible expressions are rejected eagerly at construction (see Validation), so `nextRun(from?)` always resolves a satisfiable expression within a year — its one-year scan bound is just a defensive backstop, never the path that catches a bad expression.
|
|
115
|
+
|
|
116
|
+
## Timezone interaction
|
|
117
|
+
|
|
118
|
+
If the job has `.inTimezone(tz)`, the cron parser receives a timezone-aware `dayjs` object — so `0 9 * * *` with `.inTimezone("Asia/Tokyo")` fires at 09:00 JST. See [`@warlock.js/scheduler/pin-schedule-timezone/SKILL.md`](@warlock.js/scheduler/pin-schedule-timezone/SKILL.md).
|
|
119
|
+
|
|
120
|
+
## See also
|
|
121
|
+
|
|
122
|
+
- [`@warlock.js/scheduler/schedule-fluently/SKILL.md`](@warlock.js/scheduler/schedule-fluently/SKILL.md) — the higher-level alternative for human-readable schedules
|
|
123
|
+
- [`@warlock.js/scheduler/pin-schedule-timezone/SKILL.md`](@warlock.js/scheduler/pin-schedule-timezone/SKILL.md) — pinning a cron schedule to a wall-clock timezone
|