Scheduler: edit, Run now, cron with a preview, and a schedule's runs (#19)
CI / Lint (eslint) (pull_request) Successful in 27s
CI / Test (jest) (pull_request) Successful in 26s
CI / Security (npm audit) (pull_request) Successful in 10s
CI / Scan (secrets, workflows, shell) (pull_request) Failing after 2m45s
CI / Integration (api) (pull_request) Successful in 3m37s
CI / UI (playwright) (pull_request) Successful in 2m51s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 2m35s
CI / Lint (eslint) (pull_request) Successful in 27s
CI / Test (jest) (pull_request) Successful in 26s
CI / Security (npm audit) (pull_request) Successful in 10s
CI / Scan (secrets, workflows, shell) (pull_request) Failing after 2m45s
CI / Integration (api) (pull_request) Successful in 3m37s
CI / UI (playwright) (pull_request) Successful in 2m51s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 2m35s
- Edit: PUT /api/scheduled-commands/:id changes a schedule in place (keeping its history) and works out its next run again. The create dialog doubles as the edit dialog. - Run now: POST /api/scheduled-commands/:id/run dispatches at once, records triggered_by, leaves next_run alone, and answers 409 while a previous run is still going. The dispatch body moved out of the scheduler loop into dispatchSchedule() so both share it. - Cron is offered in the dialog, and a preview shows the next three runs and the server time zone they are worked out in (GET /api/scheduled-commands/preview). Errors stay in the dialog. - Runs links to /executions?view=automated&search=scheduler:<name>; Executions now honours ?view= and ?search=. - Create and edit share scheduleInput(), which also checks daily HH:MM. - The dialog's worker list had no styles on this page (it borrows Quick Command's markup); they are now included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
777ab728c0
commit
966c2be5cc
10 files changed
+453
-97
No files matched your search
+47
-2
@@ -269,9 +269,9 @@ function definitionErrors(definition) {
|
||||
/**
|
||||
* Calculate the next run date for a scheduled command.
|
||||
*/
|
||||
function calculateNextRun(scheduleType, scheduleValue) {
|
||||
function calculateNextRun(scheduleType, scheduleValue, from) {
|
||||
const cronParser = require('cron-parser');
|
||||
const now = new Date();
|
||||
const now = from instanceof Date ? new Date(from.getTime()) : new Date();
|
||||
|
||||
if (scheduleType === 'interval') {
|
||||
const minutes = parseInt(scheduleValue);
|
||||
@@ -296,7 +296,52 @@ function calculateNextRun(scheduleType, scheduleValue) {
|
||||
throw new Error(`Unknown schedule type: ${scheduleType}`);
|
||||
}
|
||||
|
||||
/** The next `count` run times of a schedule, for the preview in the editor (#19). */
|
||||
function nextRuns(scheduleType, scheduleValue, count = 3, from = new Date()) {
|
||||
const runs = [];
|
||||
let at = from;
|
||||
for (let i = 0; i < count; i++) {
|
||||
at = calculateNextRun(scheduleType, scheduleValue, at);
|
||||
runs.push(at);
|
||||
}
|
||||
return runs;
|
||||
}
|
||||
|
||||
const SCHEDULE_TYPES = ['interval', 'hourly', 'daily', 'cron'];
|
||||
|
||||
/**
|
||||
* Check a schedule from the create or edit form (#19). Returns { error } or
|
||||
* { value: { name, command, worker_ids, schedule_type, schedule_value, next_run } }.
|
||||
*/
|
||||
function scheduleInput(body) {
|
||||
const b = body || {};
|
||||
const name = typeof b.name === 'string' ? b.name.trim() : '';
|
||||
const command = typeof b.command === 'string' ? b.command.trim() : '';
|
||||
const type = b.schedule_type;
|
||||
const value = b.schedule_value === undefined || b.schedule_value === null ? '' : String(b.schedule_value).trim();
|
||||
if (!name) return { error: 'A name is required' };
|
||||
if (name.length > 255) return { error: 'The name is too long (255 characters at most)' };
|
||||
if (!command) return { error: 'A command is required' };
|
||||
if (!Array.isArray(b.worker_ids) || b.worker_ids.length === 0 || !b.worker_ids.every(w => typeof w === 'string' && w)) {
|
||||
return { error: 'Pick at least one worker' };
|
||||
}
|
||||
if (!SCHEDULE_TYPES.includes(type)) return { error: `schedule_type must be one of: ${SCHEDULE_TYPES.join(', ')}` };
|
||||
if (!value) return { error: 'A schedule value is required' };
|
||||
if ((type === 'interval' || type === 'hourly') && !/^[1-9]\d*$/.test(value)) {
|
||||
return { error: `The ${type === 'interval' ? 'interval' : 'number of hours'} must be a whole number above 0` };
|
||||
}
|
||||
if (type === 'daily' && !/^([01]\d|2[0-3]):[0-5]\d$/.test(value)) return { error: 'The time must be HH:MM (24-hour)' };
|
||||
let next;
|
||||
try {
|
||||
next = calculateNextRun(type, value);
|
||||
} catch (e) {
|
||||
return { error: `Invalid schedule: ${e.message}` };
|
||||
}
|
||||
return { value: { name, command, worker_ids: b.worker_ids, schedule_type: type, schedule_value: value, next_run: next } };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateWebhookUrl, applyParams, evalCondition, conditionErrors, gotoErrors, calculateNextRun,
|
||||
definitionErrors, resolveParams, checkParamValue, PARAM_RULE, PARAM_TYPES, STEP_TYPES,
|
||||
nextRuns, scheduleInput, SCHEDULE_TYPES,
|
||||
};
|
||||
Reference in new issue
Block a user