mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
feat(cron): enhance one-shot job behavior and CLI options
- Default one-shot jobs to delete after success, improving job management. - Introduced `--keep-after-run` CLI option to allow users to retain one-shot jobs post-execution. - Updated documentation to clarify default behaviors and new options for one-shot jobs. - Adjusted cron job creation logic to ensure consistent handling of delete options. - Enhanced tests to validate new behaviors and ensure reliability. This update streamlines the handling of one-shot jobs, providing users with more control over job persistence and execution outcomes.
This commit is contained in:
committed by
Peter Steinberger
parent
0bb0dfc9bc
commit
ab9f06f4ff
@@ -95,6 +95,67 @@ describe("cron cli", () => {
|
||||
expect(params?.delivery?.mode).toBe("announce");
|
||||
});
|
||||
|
||||
it("infers sessionTarget from payload when --session is omitted", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "add", "--name", "Main reminder", "--cron", "* * * * *", "--system-event", "hi"],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
let addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
|
||||
let params = addCall?.[2] as { sessionTarget?: string; payload?: { kind?: string } };
|
||||
expect(params?.sessionTarget).toBe("main");
|
||||
expect(params?.payload?.kind).toBe("systemEvent");
|
||||
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "add", "--name", "Isolated task", "--cron", "* * * * *", "--message", "hello"],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
|
||||
params = addCall?.[2] as { sessionTarget?: string; payload?: { kind?: string } };
|
||||
expect(params?.sessionTarget).toBe("isolated");
|
||||
expect(params?.payload?.kind).toBe("agentTurn");
|
||||
});
|
||||
|
||||
it("supports --keep-after-run on cron add", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
"cron",
|
||||
"add",
|
||||
"--name",
|
||||
"Keep me",
|
||||
"--at",
|
||||
"20m",
|
||||
"--session",
|
||||
"main",
|
||||
"--system-event",
|
||||
"hello",
|
||||
"--keep-after-run",
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
|
||||
const params = addCall?.[2] as { deleteAfterRun?: boolean };
|
||||
expect(params?.deleteAfterRun).toBe(false);
|
||||
});
|
||||
|
||||
it("sends agent id on cron add", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user