feat: cron ISO at + delete-after-run
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Command } from "commander";
|
||||
import { parseAbsoluteTimeMs } from "../cron/parse.js";
|
||||
import type { CronJob, CronSchedule } from "../cron/types.js";
|
||||
import { danger } from "../globals.js";
|
||||
import { PROVIDER_IDS } from "../providers/registry.js";
|
||||
@@ -57,10 +58,8 @@ function parseDurationMs(input: string): number | null {
|
||||
function parseAtMs(input: string): number | null {
|
||||
const raw = input.trim();
|
||||
if (!raw) return null;
|
||||
const asNum = Number(raw);
|
||||
if (Number.isFinite(asNum) && asNum > 0) return Math.floor(asNum);
|
||||
const parsed = Date.parse(raw);
|
||||
if (Number.isFinite(parsed)) return parsed;
|
||||
const absolute = parseAbsoluteTimeMs(raw);
|
||||
if (absolute) return absolute;
|
||||
const dur = parseDurationMs(raw);
|
||||
if (dur) return Date.now() + dur;
|
||||
return null;
|
||||
@@ -294,6 +293,7 @@ export function registerCronCli(program: Command) {
|
||||
.requiredOption("--name <name>", "Job name")
|
||||
.option("--description <text>", "Optional description")
|
||||
.option("--disabled", "Create job disabled", false)
|
||||
.option("--delete-after-run", "Delete one-shot job after it succeeds", false)
|
||||
.option("--agent <id>", "Agent id for this job")
|
||||
.option("--session <target>", "Session target (main|isolated)", "main")
|
||||
.option(
|
||||
@@ -468,6 +468,7 @@ export function registerCronCli(program: Command) {
|
||||
name,
|
||||
description,
|
||||
enabled: !opts.disabled,
|
||||
deleteAfterRun: Boolean(opts.deleteAfterRun),
|
||||
agentId,
|
||||
schedule,
|
||||
sessionTarget,
|
||||
@@ -578,6 +579,8 @@ export function registerCronCli(program: Command) {
|
||||
.option("--description <text>", "Set description")
|
||||
.option("--enable", "Enable job", false)
|
||||
.option("--disable", "Disable job", false)
|
||||
.option("--delete-after-run", "Delete one-shot job after it succeeds", false)
|
||||
.option("--keep-after-run", "Keep one-shot job after it succeeds", false)
|
||||
.option("--session <target>", "Session target (main|isolated)")
|
||||
.option("--agent <id>", "Set agent id")
|
||||
.option("--clear-agent", "Unset agent and use default", false)
|
||||
@@ -630,6 +633,13 @@ export function registerCronCli(program: Command) {
|
||||
throw new Error("Choose --enable or --disable, not both");
|
||||
if (opts.enable) patch.enabled = true;
|
||||
if (opts.disable) patch.enabled = false;
|
||||
if (opts.deleteAfterRun && opts.keepAfterRun) {
|
||||
throw new Error(
|
||||
"Choose --delete-after-run or --keep-after-run, not both",
|
||||
);
|
||||
}
|
||||
if (opts.deleteAfterRun) patch.deleteAfterRun = true;
|
||||
if (opts.keepAfterRun) patch.deleteAfterRun = false;
|
||||
if (typeof opts.session === "string")
|
||||
patch.sessionTarget = opts.session;
|
||||
if (typeof opts.wake === "string") patch.wakeMode = opts.wake;
|
||||
|
||||
Reference in New Issue
Block a user