mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
fix(cron): show running status for active paused jobs (#129339)
This commit is contained in:
committed by
GitHub
parent
3be7baa1a3
commit
f498727bbd
@@ -474,27 +474,59 @@ describe("printCronList", () => {
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ label: "disabled", enabled: false, runStatus: "ok" as const, expectedStatus: "disabled" },
|
||||
{ label: "running", enabled: true, runStatus: "ok" as const, expectedStatus: "running" },
|
||||
{ label: "failed", enabled: true, runStatus: "error" as const, expectedStatus: "error" },
|
||||
{
|
||||
label: "disabled",
|
||||
enabled: false,
|
||||
running: false,
|
||||
runStatus: "ok" as const,
|
||||
expectedStatus: "disabled",
|
||||
},
|
||||
{
|
||||
label: "running",
|
||||
enabled: true,
|
||||
running: true,
|
||||
runStatus: "ok" as const,
|
||||
expectedStatus: "running",
|
||||
},
|
||||
{
|
||||
label: "paused but force-running",
|
||||
enabled: false,
|
||||
running: true,
|
||||
runStatus: "ok" as const,
|
||||
expectedStatus: "running",
|
||||
},
|
||||
{
|
||||
label: "failed",
|
||||
enabled: true,
|
||||
running: false,
|
||||
runStatus: "error" as const,
|
||||
expectedStatus: "error",
|
||||
},
|
||||
])(
|
||||
"does not let prior non-delivery override a $label automation",
|
||||
({ enabled, runStatus, expectedStatus }) => {
|
||||
({ enabled, running, runStatus, expectedStatus }) => {
|
||||
const job = createBaseJob({
|
||||
enabled,
|
||||
state: {
|
||||
lastRunStatus: runStatus,
|
||||
lastDeliveryStatus: "not-delivered",
|
||||
...(expectedStatus === "running" ? { runningAtMs: Date.now() } : {}),
|
||||
...(running ? { runningAtMs: Date.now() } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
const list = createRuntimeLogCapture();
|
||||
printCronList([job], list.runtime);
|
||||
expectLogsToInclude(list.logs, expectedStatus);
|
||||
|
||||
const show = createRuntimeLogCapture();
|
||||
printCronShow(job, show.runtime);
|
||||
|
||||
expectLogsToInclude(show.logs, `status: ${expectedStatus}`);
|
||||
expect(show.logs.join("\n")).not.toContain("ok (not delivered)");
|
||||
expect(enrichCronJsonWithStatus(job)).toMatchObject({ status: expectedStatus });
|
||||
expect(enrichCronJsonWithStatus({ jobs: [job] })).toMatchObject({
|
||||
jobs: [{ status: expectedStatus }],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -170,13 +170,13 @@ export function enrichCronJsonWithStatus(value: unknown): unknown {
|
||||
}
|
||||
|
||||
function computeStatus(job: { enabled?: unknown; state?: unknown }): string {
|
||||
if (!job.enabled) {
|
||||
return "disabled";
|
||||
}
|
||||
const state = asOptionalRecord(job.state) ?? {};
|
||||
if (state.runningAtMs) {
|
||||
return "running";
|
||||
}
|
||||
if (!job.enabled) {
|
||||
return "disabled";
|
||||
}
|
||||
return typeof state.lastRunStatus === "string"
|
||||
? state.lastRunStatus
|
||||
: typeof state.lastStatus === "string"
|
||||
|
||||
Reference in New Issue
Block a user