crewly 1.4.63 → 1.4.64
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/backend/backend/src/controllers/scheduler/unified-scheduler.controller.d.ts +91 -0
- package/dist/backend/backend/src/controllers/scheduler/unified-scheduler.controller.d.ts.map +1 -0
- package/dist/backend/backend/src/controllers/scheduler/unified-scheduler.controller.js +290 -0
- package/dist/backend/backend/src/controllers/scheduler/unified-scheduler.controller.js.map +1 -0
- package/dist/backend/backend/src/routes/api.routes.d.ts.map +1 -1
- package/dist/backend/backend/src/routes/api.routes.js +3 -0
- package/dist/backend/backend/src/routes/api.routes.js.map +1 -1
- package/dist/backend/backend/src/routes/modules/unified-scheduler.routes.d.ts +27 -0
- package/dist/backend/backend/src/routes/modules/unified-scheduler.routes.d.ts.map +1 -0
- package/dist/backend/backend/src/routes/modules/unified-scheduler.routes.js +40 -0
- package/dist/backend/backend/src/routes/modules/unified-scheduler.routes.js.map +1 -0
- package/dist/backend/backend/src/services/index.d.ts +1 -0
- package/dist/backend/backend/src/services/index.d.ts.map +1 -1
- package/dist/backend/backend/src/services/index.js +1 -0
- package/dist/backend/backend/src/services/index.js.map +1 -1
- package/dist/backend/backend/src/services/workflow/unified-scheduler.service.d.ts +234 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.service.js +636 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.service.js.map +1 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.types.d.ts +156 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.types.d.ts.map +1 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.types.js +81 -0
- package/dist/backend/backend/src/services/workflow/unified-scheduler.types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Scheduler Service
|
|
3
|
+
*
|
|
4
|
+
* Consolidates cron, interval, and idle-based scheduling into a single
|
|
5
|
+
* persistent service with agent auto-start capabilities.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Cron schedules: standard 5-field expressions
|
|
9
|
+
* - Interval schedules: fixed-interval triggers
|
|
10
|
+
* - Idle schedules: trigger when agent has been idle for N minutes
|
|
11
|
+
* - Persistent storage in ~/.crewly/unified-schedules.json
|
|
12
|
+
* - Auto-start agents that are offline when triggered
|
|
13
|
+
* - Auto-pause after maxConsecutiveTriggers without agent response
|
|
14
|
+
* - Manual trigger, pause, and resume
|
|
15
|
+
*
|
|
16
|
+
* Runs a 60-second evaluation loop that checks all active schedules
|
|
17
|
+
* and triggers those that are due.
|
|
18
|
+
*
|
|
19
|
+
* @module services/workflow/unified-scheduler.service
|
|
20
|
+
*/
|
|
21
|
+
import { EventEmitter } from 'events';
|
|
22
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
23
|
+
import { join } from 'path';
|
|
24
|
+
import { homedir } from 'os';
|
|
25
|
+
import { randomUUID } from 'crypto';
|
|
26
|
+
import { LoggerService } from '../core/logger.service.js';
|
|
27
|
+
import { UNIFIED_SCHEDULER_CONSTANTS, validateCreateRequest, } from './unified-scheduler.types.js';
|
|
28
|
+
// =============================================================================
|
|
29
|
+
// Service
|
|
30
|
+
// =============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* UnifiedSchedulerService manages all schedule types (cron, interval, idle)
|
|
33
|
+
* in a single persistent store with a 60-second evaluation loop.
|
|
34
|
+
*
|
|
35
|
+
* Uses sendMessageToAgent (via callback) for message delivery and
|
|
36
|
+
* supports auto-starting offline agents.
|
|
37
|
+
*/
|
|
38
|
+
export class UnifiedSchedulerService extends EventEmitter {
|
|
39
|
+
static instance = null;
|
|
40
|
+
logger;
|
|
41
|
+
storagePath;
|
|
42
|
+
/** All schedules indexed by ID */
|
|
43
|
+
schedules = new Map();
|
|
44
|
+
/** Evaluation loop timer */
|
|
45
|
+
evalTimer = null;
|
|
46
|
+
/** Whether the eval loop is running */
|
|
47
|
+
running = false;
|
|
48
|
+
/** Timestamp of last evaluation cycle */
|
|
49
|
+
lastEvaluatedAt = null;
|
|
50
|
+
/** Total triggers since service start */
|
|
51
|
+
totalTriggersSinceStart = 0;
|
|
52
|
+
/**
|
|
53
|
+
* Callback for sending messages to agents.
|
|
54
|
+
* Set via setMessageCallback() — decouples from AgentRegistrationService.
|
|
55
|
+
*/
|
|
56
|
+
messageCallback = null;
|
|
57
|
+
/**
|
|
58
|
+
* Callback for checking if an agent is online.
|
|
59
|
+
* Set via setAgentStatusCallback().
|
|
60
|
+
*/
|
|
61
|
+
agentStatusCallback = null;
|
|
62
|
+
/**
|
|
63
|
+
* Callback for starting an offline agent.
|
|
64
|
+
* Set via setAgentStartCallback().
|
|
65
|
+
*/
|
|
66
|
+
agentStartCallback = null;
|
|
67
|
+
/**
|
|
68
|
+
* Callback for checking agent idle status.
|
|
69
|
+
* Set via setIdleCheckCallback().
|
|
70
|
+
*/
|
|
71
|
+
idleCheckCallback = null;
|
|
72
|
+
constructor(crewlyHome) {
|
|
73
|
+
super();
|
|
74
|
+
this.logger = LoggerService.getInstance().createComponentLogger('UnifiedScheduler');
|
|
75
|
+
const home = crewlyHome ?? join(homedir(), '.crewly');
|
|
76
|
+
this.storagePath = join(home, UNIFIED_SCHEDULER_CONSTANTS.STORAGE_FILE);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the singleton instance.
|
|
80
|
+
*
|
|
81
|
+
* @param crewlyHome - Override ~/.crewly path (for testing)
|
|
82
|
+
* @returns Service instance
|
|
83
|
+
*/
|
|
84
|
+
static getInstance(crewlyHome) {
|
|
85
|
+
if (!UnifiedSchedulerService.instance) {
|
|
86
|
+
UnifiedSchedulerService.instance = new UnifiedSchedulerService(crewlyHome);
|
|
87
|
+
}
|
|
88
|
+
return UnifiedSchedulerService.instance;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reset the singleton (for testing).
|
|
92
|
+
*/
|
|
93
|
+
static resetInstance() {
|
|
94
|
+
if (UnifiedSchedulerService.instance) {
|
|
95
|
+
UnifiedSchedulerService.instance.stop();
|
|
96
|
+
}
|
|
97
|
+
UnifiedSchedulerService.instance = null;
|
|
98
|
+
}
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Dependency Injection (callbacks)
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
/**
|
|
103
|
+
* Set the callback for sending messages to agents.
|
|
104
|
+
*
|
|
105
|
+
* @param callback - Function that sends a message to an agent by session name
|
|
106
|
+
*/
|
|
107
|
+
setMessageCallback(callback) {
|
|
108
|
+
this.messageCallback = callback;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set the callback for checking if an agent is online.
|
|
112
|
+
*
|
|
113
|
+
* @param callback - Returns true if the agent is currently active
|
|
114
|
+
*/
|
|
115
|
+
setAgentStatusCallback(callback) {
|
|
116
|
+
this.agentStatusCallback = callback;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Set the callback for starting an offline agent.
|
|
120
|
+
*
|
|
121
|
+
* @param callback - Starts the agent and returns true if successful
|
|
122
|
+
*/
|
|
123
|
+
setAgentStartCallback(callback) {
|
|
124
|
+
this.agentStartCallback = callback;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Set the callback for checking agent idle status.
|
|
128
|
+
*
|
|
129
|
+
* @param callback - Returns idle status and idle duration
|
|
130
|
+
*/
|
|
131
|
+
setIdleCheckCallback(callback) {
|
|
132
|
+
this.idleCheckCallback = callback;
|
|
133
|
+
}
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Lifecycle
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Start the scheduler evaluation loop.
|
|
139
|
+
*
|
|
140
|
+
* Loads persisted schedules from disk and begins the 60-second
|
|
141
|
+
* evaluation cycle.
|
|
142
|
+
*/
|
|
143
|
+
start() {
|
|
144
|
+
if (this.running)
|
|
145
|
+
return;
|
|
146
|
+
this.loadFromDisk();
|
|
147
|
+
this.running = true;
|
|
148
|
+
this.evalTimer = setInterval(() => {
|
|
149
|
+
this.evaluate().catch(err => {
|
|
150
|
+
this.logger.error('Evaluation cycle failed', {
|
|
151
|
+
error: err instanceof Error ? err.message : String(err),
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}, UNIFIED_SCHEDULER_CONSTANTS.EVAL_INTERVAL_MS);
|
|
155
|
+
this.logger.info('Unified Scheduler started', {
|
|
156
|
+
scheduleCount: this.schedules.size,
|
|
157
|
+
activeCount: this.getActiveCount(),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Stop the scheduler evaluation loop.
|
|
162
|
+
*/
|
|
163
|
+
stop() {
|
|
164
|
+
if (this.evalTimer) {
|
|
165
|
+
clearInterval(this.evalTimer);
|
|
166
|
+
this.evalTimer = null;
|
|
167
|
+
}
|
|
168
|
+
this.running = false;
|
|
169
|
+
this.logger.info('Unified Scheduler stopped');
|
|
170
|
+
}
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// CRUD
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
/**
|
|
175
|
+
* Create a new schedule.
|
|
176
|
+
*
|
|
177
|
+
* @param request - Schedule creation request
|
|
178
|
+
* @returns Created schedule
|
|
179
|
+
* @throws Error if validation fails
|
|
180
|
+
*/
|
|
181
|
+
create(request) {
|
|
182
|
+
const validationError = validateCreateRequest(request);
|
|
183
|
+
if (validationError) {
|
|
184
|
+
throw new Error(validationError);
|
|
185
|
+
}
|
|
186
|
+
const now = new Date().toISOString();
|
|
187
|
+
const schedule = {
|
|
188
|
+
id: randomUUID(),
|
|
189
|
+
target: request.target,
|
|
190
|
+
type: request.type,
|
|
191
|
+
cron: request.cron,
|
|
192
|
+
intervalMinutes: request.intervalMinutes,
|
|
193
|
+
idleTimeoutMinutes: request.idleTimeoutMinutes,
|
|
194
|
+
message: request.message,
|
|
195
|
+
enabled: request.enabled !== false,
|
|
196
|
+
autoStart: request.autoStart !== false,
|
|
197
|
+
maxConsecutiveTriggers: request.maxConsecutiveTriggers ?? UNIFIED_SCHEDULER_CONSTANTS.DEFAULT_MAX_CONSECUTIVE,
|
|
198
|
+
createdAt: now,
|
|
199
|
+
updatedAt: now,
|
|
200
|
+
lastTriggeredAt: null,
|
|
201
|
+
triggerCount: 0,
|
|
202
|
+
consecutiveTriggers: 0,
|
|
203
|
+
status: (request.enabled !== false) ? 'active' : 'paused',
|
|
204
|
+
};
|
|
205
|
+
this.schedules.set(schedule.id, schedule);
|
|
206
|
+
this.persist();
|
|
207
|
+
this.logger.info('Schedule created', {
|
|
208
|
+
id: schedule.id,
|
|
209
|
+
type: schedule.type,
|
|
210
|
+
target: schedule.target,
|
|
211
|
+
status: schedule.status,
|
|
212
|
+
});
|
|
213
|
+
return schedule;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get a schedule by ID.
|
|
217
|
+
*
|
|
218
|
+
* @param id - Schedule ID
|
|
219
|
+
* @returns Schedule or null
|
|
220
|
+
*/
|
|
221
|
+
get(id) {
|
|
222
|
+
return this.schedules.get(id) ?? null;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* List all schedules, optionally filtered by target session.
|
|
226
|
+
*
|
|
227
|
+
* @param target - Optional session name filter
|
|
228
|
+
* @returns Array of schedules
|
|
229
|
+
*/
|
|
230
|
+
list(target) {
|
|
231
|
+
const all = Array.from(this.schedules.values());
|
|
232
|
+
if (target) {
|
|
233
|
+
return all.filter(s => s.target === target);
|
|
234
|
+
}
|
|
235
|
+
return all;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Update an existing schedule.
|
|
239
|
+
*
|
|
240
|
+
* @param id - Schedule ID
|
|
241
|
+
* @param updates - Partial update fields
|
|
242
|
+
* @returns Updated schedule or null if not found
|
|
243
|
+
*/
|
|
244
|
+
update(id, updates) {
|
|
245
|
+
const schedule = this.schedules.get(id);
|
|
246
|
+
if (!schedule)
|
|
247
|
+
return null;
|
|
248
|
+
if (updates.cron !== undefined)
|
|
249
|
+
schedule.cron = updates.cron;
|
|
250
|
+
if (updates.intervalMinutes !== undefined)
|
|
251
|
+
schedule.intervalMinutes = updates.intervalMinutes;
|
|
252
|
+
if (updates.idleTimeoutMinutes !== undefined)
|
|
253
|
+
schedule.idleTimeoutMinutes = updates.idleTimeoutMinutes;
|
|
254
|
+
if (updates.message !== undefined)
|
|
255
|
+
schedule.message = updates.message;
|
|
256
|
+
if (updates.autoStart !== undefined)
|
|
257
|
+
schedule.autoStart = updates.autoStart;
|
|
258
|
+
if (updates.maxConsecutiveTriggers !== undefined)
|
|
259
|
+
schedule.maxConsecutiveTriggers = updates.maxConsecutiveTriggers;
|
|
260
|
+
if (updates.enabled !== undefined) {
|
|
261
|
+
schedule.enabled = updates.enabled;
|
|
262
|
+
schedule.status = updates.enabled ? 'active' : 'paused';
|
|
263
|
+
}
|
|
264
|
+
schedule.updatedAt = new Date().toISOString();
|
|
265
|
+
this.schedules.set(id, schedule);
|
|
266
|
+
this.persist();
|
|
267
|
+
return schedule;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Delete a schedule.
|
|
271
|
+
*
|
|
272
|
+
* @param id - Schedule ID
|
|
273
|
+
* @returns True if deleted
|
|
274
|
+
*/
|
|
275
|
+
delete(id) {
|
|
276
|
+
const deleted = this.schedules.delete(id);
|
|
277
|
+
if (deleted) {
|
|
278
|
+
this.persist();
|
|
279
|
+
this.logger.info('Schedule deleted', { id });
|
|
280
|
+
}
|
|
281
|
+
return deleted;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Pause a schedule.
|
|
285
|
+
*
|
|
286
|
+
* @param id - Schedule ID
|
|
287
|
+
* @returns Updated schedule or null
|
|
288
|
+
*/
|
|
289
|
+
pause(id) {
|
|
290
|
+
const schedule = this.schedules.get(id);
|
|
291
|
+
if (!schedule)
|
|
292
|
+
return null;
|
|
293
|
+
schedule.enabled = false;
|
|
294
|
+
schedule.status = 'paused';
|
|
295
|
+
schedule.updatedAt = new Date().toISOString();
|
|
296
|
+
this.schedules.set(id, schedule);
|
|
297
|
+
this.persist();
|
|
298
|
+
this.logger.info('Schedule paused', { id, target: schedule.target });
|
|
299
|
+
return schedule;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Resume a paused schedule.
|
|
303
|
+
*
|
|
304
|
+
* @param id - Schedule ID
|
|
305
|
+
* @returns Updated schedule or null
|
|
306
|
+
*/
|
|
307
|
+
resume(id) {
|
|
308
|
+
const schedule = this.schedules.get(id);
|
|
309
|
+
if (!schedule)
|
|
310
|
+
return null;
|
|
311
|
+
schedule.enabled = true;
|
|
312
|
+
schedule.status = 'active';
|
|
313
|
+
schedule.consecutiveTriggers = 0;
|
|
314
|
+
schedule.updatedAt = new Date().toISOString();
|
|
315
|
+
this.schedules.set(id, schedule);
|
|
316
|
+
this.persist();
|
|
317
|
+
this.logger.info('Schedule resumed', { id, target: schedule.target });
|
|
318
|
+
return schedule;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Manually trigger a schedule now, regardless of timing.
|
|
322
|
+
*
|
|
323
|
+
* @param id - Schedule ID
|
|
324
|
+
* @returns True if triggered successfully
|
|
325
|
+
*/
|
|
326
|
+
async triggerNow(id) {
|
|
327
|
+
const schedule = this.schedules.get(id);
|
|
328
|
+
if (!schedule)
|
|
329
|
+
return false;
|
|
330
|
+
return this.executeSchedule(schedule);
|
|
331
|
+
}
|
|
332
|
+
// ---------------------------------------------------------------------------
|
|
333
|
+
// Health
|
|
334
|
+
// ---------------------------------------------------------------------------
|
|
335
|
+
/**
|
|
336
|
+
* Get scheduler health and statistics.
|
|
337
|
+
*
|
|
338
|
+
* @returns Health stats
|
|
339
|
+
*/
|
|
340
|
+
getHealth() {
|
|
341
|
+
const all = Array.from(this.schedules.values());
|
|
342
|
+
const byType = { cron: 0, interval: 0, idle: 0 };
|
|
343
|
+
let activeCount = 0;
|
|
344
|
+
let pausedCount = 0;
|
|
345
|
+
for (const s of all) {
|
|
346
|
+
byType[s.type]++;
|
|
347
|
+
if (s.status === 'active')
|
|
348
|
+
activeCount++;
|
|
349
|
+
if (s.status === 'paused')
|
|
350
|
+
pausedCount++;
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
running: this.running,
|
|
354
|
+
activeCount,
|
|
355
|
+
pausedCount,
|
|
356
|
+
totalCount: all.length,
|
|
357
|
+
totalTriggers: this.totalTriggersSinceStart,
|
|
358
|
+
lastEvaluatedAt: this.lastEvaluatedAt,
|
|
359
|
+
byType,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// Evaluation Loop
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
/**
|
|
366
|
+
* Evaluate all active schedules and trigger those that are due.
|
|
367
|
+
*
|
|
368
|
+
* Called every 60 seconds by the eval timer. Checks each schedule
|
|
369
|
+
* type against its timing criteria and executes if due.
|
|
370
|
+
*/
|
|
371
|
+
async evaluate() {
|
|
372
|
+
this.lastEvaluatedAt = new Date().toISOString();
|
|
373
|
+
const actives = Array.from(this.schedules.values()).filter(s => s.enabled && s.status === 'active');
|
|
374
|
+
for (const schedule of actives) {
|
|
375
|
+
try {
|
|
376
|
+
const isDue = await this.isScheduleDue(schedule);
|
|
377
|
+
if (isDue) {
|
|
378
|
+
await this.executeSchedule(schedule);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
this.logger.error('Schedule evaluation failed', {
|
|
383
|
+
id: schedule.id,
|
|
384
|
+
type: schedule.type,
|
|
385
|
+
error: err instanceof Error ? err.message : String(err),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Check if a schedule is due for triggering.
|
|
392
|
+
*
|
|
393
|
+
* @param schedule - Schedule to check
|
|
394
|
+
* @returns True if the schedule should trigger now
|
|
395
|
+
*/
|
|
396
|
+
async isScheduleDue(schedule) {
|
|
397
|
+
const now = Date.now();
|
|
398
|
+
switch (schedule.type) {
|
|
399
|
+
case 'cron':
|
|
400
|
+
return this.isCronDue(schedule);
|
|
401
|
+
case 'interval': {
|
|
402
|
+
if (!schedule.intervalMinutes)
|
|
403
|
+
return false;
|
|
404
|
+
const intervalMs = schedule.intervalMinutes * 60_000;
|
|
405
|
+
const lastTrigger = schedule.lastTriggeredAt
|
|
406
|
+
? new Date(schedule.lastTriggeredAt).getTime()
|
|
407
|
+
: new Date(schedule.createdAt).getTime();
|
|
408
|
+
return (now - lastTrigger) >= intervalMs;
|
|
409
|
+
}
|
|
410
|
+
case 'idle': {
|
|
411
|
+
if (!this.idleCheckCallback)
|
|
412
|
+
return false;
|
|
413
|
+
const timeout = schedule.idleTimeoutMinutes ?? UNIFIED_SCHEDULER_CONSTANTS.DEFAULT_IDLE_TIMEOUT_MINUTES;
|
|
414
|
+
const { idle, idleMinutes } = await this.idleCheckCallback(schedule.target);
|
|
415
|
+
return idle && idleMinutes >= timeout;
|
|
416
|
+
}
|
|
417
|
+
default:
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Check if a cron schedule is due (within the current evaluation window).
|
|
423
|
+
*
|
|
424
|
+
* Compares the cron expression against the current time.
|
|
425
|
+
* Uses minute-level granularity (matches eval loop frequency).
|
|
426
|
+
*
|
|
427
|
+
* @param schedule - Cron schedule to check
|
|
428
|
+
* @returns True if the current minute matches the cron expression
|
|
429
|
+
*/
|
|
430
|
+
isCronDue(schedule) {
|
|
431
|
+
if (!schedule.cron)
|
|
432
|
+
return false;
|
|
433
|
+
const now = new Date();
|
|
434
|
+
const fields = schedule.cron.trim().split(/\s+/);
|
|
435
|
+
if (fields.length !== 5)
|
|
436
|
+
return false;
|
|
437
|
+
const [minuteField, hourField, domField, monthField, dowField] = fields;
|
|
438
|
+
const matchField = (field, value, max) => {
|
|
439
|
+
if (field === '*')
|
|
440
|
+
return true;
|
|
441
|
+
// Handle comma-separated values
|
|
442
|
+
const parts = field.split(',');
|
|
443
|
+
for (const part of parts) {
|
|
444
|
+
// Handle range (e.g., 1-5)
|
|
445
|
+
if (part.includes('-')) {
|
|
446
|
+
const [start, end] = part.split('-').map(Number);
|
|
447
|
+
if (value >= start && value <= end)
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
// Handle step (e.g., */5)
|
|
451
|
+
else if (part.includes('/')) {
|
|
452
|
+
const [base, step] = part.split('/');
|
|
453
|
+
const stepNum = Number(step);
|
|
454
|
+
const baseNum = base === '*' ? 0 : Number(base);
|
|
455
|
+
if (stepNum > 0 && (value - baseNum) % stepNum === 0 && value >= baseNum)
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
// Exact match
|
|
459
|
+
else if (Number(part) === value) {
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
};
|
|
465
|
+
const minute = now.getMinutes();
|
|
466
|
+
const hour = now.getHours();
|
|
467
|
+
const dom = now.getDate();
|
|
468
|
+
const month = now.getMonth() + 1;
|
|
469
|
+
const dow = now.getDay();
|
|
470
|
+
if (!matchField(minuteField, minute, 59))
|
|
471
|
+
return false;
|
|
472
|
+
if (!matchField(hourField, hour, 23))
|
|
473
|
+
return false;
|
|
474
|
+
if (!matchField(domField, dom, 31))
|
|
475
|
+
return false;
|
|
476
|
+
if (!matchField(monthField, month, 12))
|
|
477
|
+
return false;
|
|
478
|
+
if (!matchField(dowField, dow, 6))
|
|
479
|
+
return false;
|
|
480
|
+
// Prevent double-trigger in the same minute
|
|
481
|
+
if (schedule.lastTriggeredAt) {
|
|
482
|
+
const lastTrigger = new Date(schedule.lastTriggeredAt);
|
|
483
|
+
if (lastTrigger.getMinutes() === minute &&
|
|
484
|
+
lastTrigger.getHours() === hour &&
|
|
485
|
+
lastTrigger.getDate() === dom) {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Execute a schedule: send message to agent, handle auto-start,
|
|
493
|
+
* track consecutive triggers, and auto-pause if limit reached.
|
|
494
|
+
*
|
|
495
|
+
* @param schedule - Schedule to execute
|
|
496
|
+
* @returns True if message was delivered successfully
|
|
497
|
+
*/
|
|
498
|
+
async executeSchedule(schedule) {
|
|
499
|
+
this.logger.info('Triggering schedule', {
|
|
500
|
+
id: schedule.id,
|
|
501
|
+
type: schedule.type,
|
|
502
|
+
target: schedule.target,
|
|
503
|
+
triggerCount: schedule.triggerCount,
|
|
504
|
+
});
|
|
505
|
+
// Check if agent is online (if we have the callback)
|
|
506
|
+
let agentOnline = true;
|
|
507
|
+
if (this.agentStatusCallback) {
|
|
508
|
+
agentOnline = await this.agentStatusCallback(schedule.target);
|
|
509
|
+
}
|
|
510
|
+
// Auto-start if offline and autoStart is enabled
|
|
511
|
+
if (!agentOnline && schedule.autoStart && this.agentStartCallback) {
|
|
512
|
+
this.logger.info('Auto-starting offline agent', { target: schedule.target });
|
|
513
|
+
const started = await this.agentStartCallback(schedule.target);
|
|
514
|
+
if (!started) {
|
|
515
|
+
this.logger.warn('Failed to auto-start agent', { target: schedule.target });
|
|
516
|
+
schedule.error = 'Agent auto-start failed';
|
|
517
|
+
this.schedules.set(schedule.id, schedule);
|
|
518
|
+
this.persist();
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
agentOnline = true;
|
|
522
|
+
}
|
|
523
|
+
if (!agentOnline) {
|
|
524
|
+
this.logger.warn('Agent offline, skipping trigger', { target: schedule.target });
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
// Send message
|
|
528
|
+
let success = false;
|
|
529
|
+
if (this.messageCallback) {
|
|
530
|
+
const result = await this.messageCallback(schedule.target, schedule.message);
|
|
531
|
+
success = result.success;
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
this.logger.warn('No message callback set — cannot deliver message');
|
|
535
|
+
}
|
|
536
|
+
// Update tracking
|
|
537
|
+
const now = new Date().toISOString();
|
|
538
|
+
schedule.lastTriggeredAt = now;
|
|
539
|
+
schedule.triggerCount++;
|
|
540
|
+
schedule.updatedAt = now;
|
|
541
|
+
this.totalTriggersSinceStart++;
|
|
542
|
+
if (success) {
|
|
543
|
+
schedule.consecutiveTriggers++;
|
|
544
|
+
}
|
|
545
|
+
// Auto-pause if consecutive trigger limit reached
|
|
546
|
+
if (schedule.consecutiveTriggers >= schedule.maxConsecutiveTriggers) {
|
|
547
|
+
schedule.status = 'paused';
|
|
548
|
+
schedule.enabled = false;
|
|
549
|
+
schedule.error = `Auto-paused after ${schedule.consecutiveTriggers} consecutive triggers without agent response`;
|
|
550
|
+
this.logger.warn('Schedule auto-paused (max consecutive triggers)', {
|
|
551
|
+
id: schedule.id,
|
|
552
|
+
target: schedule.target,
|
|
553
|
+
consecutiveTriggers: schedule.consecutiveTriggers,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
this.schedules.set(schedule.id, schedule);
|
|
557
|
+
this.persist();
|
|
558
|
+
this.emit('triggered', { scheduleId: schedule.id, target: schedule.target, success });
|
|
559
|
+
return success;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Reset the consecutive trigger counter for a target agent.
|
|
563
|
+
*
|
|
564
|
+
* Called when an agent shows activity (e.g., sends a message, completes a task).
|
|
565
|
+
* This prevents auto-pausing schedules for responsive agents.
|
|
566
|
+
*
|
|
567
|
+
* @param target - Agent session name
|
|
568
|
+
*/
|
|
569
|
+
resetConsecutiveTriggers(target) {
|
|
570
|
+
for (const schedule of this.schedules.values()) {
|
|
571
|
+
if (schedule.target === target && schedule.consecutiveTriggers > 0) {
|
|
572
|
+
schedule.consecutiveTriggers = 0;
|
|
573
|
+
this.schedules.set(schedule.id, schedule);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
this.persist();
|
|
577
|
+
}
|
|
578
|
+
// ---------------------------------------------------------------------------
|
|
579
|
+
// Persistence
|
|
580
|
+
// ---------------------------------------------------------------------------
|
|
581
|
+
/**
|
|
582
|
+
* Save all schedules to disk.
|
|
583
|
+
*/
|
|
584
|
+
persist() {
|
|
585
|
+
try {
|
|
586
|
+
const dir = this.storagePath.replace(/\/[^/]+$/, '');
|
|
587
|
+
if (!existsSync(dir)) {
|
|
588
|
+
mkdirSync(dir, { recursive: true });
|
|
589
|
+
}
|
|
590
|
+
const store = {
|
|
591
|
+
version: UNIFIED_SCHEDULER_CONSTANTS.SCHEMA_VERSION,
|
|
592
|
+
updatedAt: new Date().toISOString(),
|
|
593
|
+
schedules: Array.from(this.schedules.values()),
|
|
594
|
+
};
|
|
595
|
+
writeFileSync(this.storagePath, JSON.stringify(store, null, 2), 'utf-8');
|
|
596
|
+
}
|
|
597
|
+
catch (err) {
|
|
598
|
+
this.logger.error('Failed to persist schedules', {
|
|
599
|
+
error: err instanceof Error ? err.message : String(err),
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Load schedules from disk.
|
|
605
|
+
*/
|
|
606
|
+
loadFromDisk() {
|
|
607
|
+
try {
|
|
608
|
+
if (!existsSync(this.storagePath))
|
|
609
|
+
return;
|
|
610
|
+
const raw = readFileSync(this.storagePath, 'utf-8');
|
|
611
|
+
const store = JSON.parse(raw);
|
|
612
|
+
this.schedules.clear();
|
|
613
|
+
for (const schedule of store.schedules) {
|
|
614
|
+
this.schedules.set(schedule.id, schedule);
|
|
615
|
+
}
|
|
616
|
+
this.logger.info('Loaded schedules from disk', {
|
|
617
|
+
count: this.schedules.size,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
catch (err) {
|
|
621
|
+
this.logger.error('Failed to load schedules from disk', {
|
|
622
|
+
error: err instanceof Error ? err.message : String(err),
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
// ---------------------------------------------------------------------------
|
|
627
|
+
// Helpers
|
|
628
|
+
// ---------------------------------------------------------------------------
|
|
629
|
+
/**
|
|
630
|
+
* Get count of active schedules.
|
|
631
|
+
*/
|
|
632
|
+
getActiveCount() {
|
|
633
|
+
return Array.from(this.schedules.values()).filter(s => s.status === 'active').length;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
//# sourceMappingURL=unified-scheduler.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-scheduler.service.js","sourceRoot":"","sources":["../../../../../../backend/src/services/workflow/unified-scheduler.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,aAAa,EAAwB,MAAM,2BAA2B,CAAC;AAShF,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AAEtC,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;;;;;GAMG;AACH,MAAM,OAAO,uBAAwB,SAAQ,YAAY;IAC/C,MAAM,CAAC,QAAQ,GAAmC,IAAI,CAAC;IAC9C,MAAM,CAAkB;IACxB,WAAW,CAAS;IAErC,kCAAkC;IAC1B,SAAS,GAAiC,IAAI,GAAG,EAAE,CAAC;IAC5D,4BAA4B;IACpB,SAAS,GAA0C,IAAI,CAAC;IAChE,uC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