@yemi33/minions 0.1.62 → 0.1.63
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 +5 -0
- package/engine/scheduler.js +22 -28
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/engine/scheduler.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* engine/scheduler.js
|
|
3
|
-
* Zero dependencies
|
|
2
|
+
* engine/scheduler.js -- Cron-style scheduled task discovery.
|
|
3
|
+
* Zero dependencies -- uses only Node.js built-ins.
|
|
4
4
|
*
|
|
5
5
|
* Config schema:
|
|
6
6
|
* config.schedules: Array<{
|
|
7
|
-
* id: string,
|
|
8
|
-
* cron: string,
|
|
9
|
-
* type: string,
|
|
10
|
-
* title: string,
|
|
7
|
+
* id: string, -- unique schedule ID
|
|
8
|
+
* cron: string, -- simplified cron: "minute hour dayOfWeek" (0=Sun..6=Sat)
|
|
9
|
+
* type: string, -- work item type (implement, test, explore, ask, etc.)
|
|
10
|
+
* title: string, -- work item title
|
|
11
11
|
* description?: string,
|
|
12
|
-
* project?: string,
|
|
13
|
-
* agent?: string,
|
|
14
|
-
* enabled?: boolean
|
|
12
|
+
* project?: string, -- target project name
|
|
13
|
+
* agent?: string, -- preferred agent ID
|
|
14
|
+
* enabled?: boolean -- default true
|
|
15
15
|
* }>
|
|
16
16
|
*
|
|
17
17
|
* Cron field syntax:
|
|
18
|
-
* *
|
|
19
|
-
* N
|
|
20
|
-
* N,M
|
|
21
|
-
* * /N
|
|
18
|
+
* * -- every value
|
|
19
|
+
* N -- exact value (e.g., "0" = minute 0, "2" = 2am, "1" = Monday)
|
|
20
|
+
* N,M -- multiple values (e.g., "1,3,5" = Mon/Wed/Fri)
|
|
21
|
+
* * /N -- every Nth value (e.g., "* /15" = every 15 minutes) [no space -- formatting only]
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
const fs = require('fs');
|
|
@@ -28,13 +28,9 @@ const { safeJson, safeWrite, mutateJsonFileLocked } = shared;
|
|
|
28
28
|
|
|
29
29
|
const SCHEDULE_RUNS_PATH = path.join(__dirname, 'schedule-runs.json');
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* @param {number} min — minimum valid value (0 for minute/dow, 0 for hour)
|
|
35
|
-
* @param {number} max — maximum valid value (59 for minute, 23 for hour, 6 for dow)
|
|
36
|
-
* @returns {function(number): boolean}
|
|
37
|
-
*/
|
|
31
|
+
// Parse a single cron field into a matcher function.
|
|
32
|
+
// field: e.g., "*", "5", "1,3,5", "*/15"
|
|
33
|
+
// min/max: valid range (0-59 for minute, 0-23 for hour, 0-6 for dow)
|
|
38
34
|
function parseCronField(field, min, max) {
|
|
39
35
|
field = field.trim();
|
|
40
36
|
if (field === '*') return () => true;
|
|
@@ -59,11 +55,9 @@ function parseCronField(field, min, max) {
|
|
|
59
55
|
return () => false;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
* @returns {{ matches: function(Date): boolean }} or null if invalid
|
|
66
|
-
*/
|
|
58
|
+
// Parse a 3-field cron expression: "minute hour dayOfWeek"
|
|
59
|
+
// expr: e.g., "0 2 *" (2am daily), "0 9 1" (9am Monday), "*/30 * *" (every 30 min)
|
|
60
|
+
// Returns { matches(date) } or null if invalid
|
|
67
61
|
function parseCronExpr(expr) {
|
|
68
62
|
if (!expr || typeof expr !== 'string') return null;
|
|
69
63
|
const parts = expr.trim().split(/\s+/);
|
|
@@ -86,7 +80,7 @@ function parseCronExpr(expr) {
|
|
|
86
80
|
* Check if a schedule should fire now, given its last run time.
|
|
87
81
|
* Prevents double-firing within the same minute window.
|
|
88
82
|
* @param {{ cron: string }} schedule
|
|
89
|
-
* @param {string|null} lastRunAt
|
|
83
|
+
* @param {string|null} lastRunAt -- ISO timestamp of last run
|
|
90
84
|
* @returns {boolean}
|
|
91
85
|
*/
|
|
92
86
|
function shouldRunNow(schedule, lastRunAt) {
|
|
@@ -108,8 +102,8 @@ function shouldRunNow(schedule, lastRunAt) {
|
|
|
108
102
|
|
|
109
103
|
/**
|
|
110
104
|
* Discover work items from configured schedules.
|
|
111
|
-
* @param {object} config
|
|
112
|
-
* @returns {Array<object>}
|
|
105
|
+
* @param {object} config -- full config object
|
|
106
|
+
* @returns {Array<object>} -- work items to create
|
|
113
107
|
*/
|
|
114
108
|
function discoverScheduledWork(config) {
|
|
115
109
|
const schedules = config.schedules;
|
package/package.json
CHANGED