Skip to content

Commit 678dfb6

Browse files
committed
fix(cron): show running status for active paused jobs
1 parent 13934fe commit 678dfb6

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

‎src/cli/cron-cli/shared.test.ts‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,27 +434,59 @@ describe("printCronList", () => {
434434
);
435435

436436
it.each([
437-
{ label: "disabled", enabled: false, runStatus: "ok" as const, expectedStatus: "disabled" },
438-
{ label: "running", enabled: true, runStatus: "ok" as const, expectedStatus: "running" },
439-
{ label: "failed", enabled: true, runStatus: "error" as const, expectedStatus: "error" },
437+
{
438+
label: "disabled",
439+
enabled: false,
440+
running: false,
441+
runStatus: "ok" as const,
442+
expectedStatus: "disabled",
443+
},
444+
{
445+
label: "running",
446+
enabled: true,
447+
running: true,
448+
runStatus: "ok" as const,
449+
expectedStatus: "running",
450+
},
451+
{
452+
label: "paused but force-running",
453+
enabled: false,
454+
running: true,
455+
runStatus: "ok" as const,
456+
expectedStatus: "running",
457+
},
458+
{
459+
label: "failed",
460+
enabled: true,
461+
running: false,
462+
runStatus: "error" as const,
463+
expectedStatus: "error",
464+
},
440465
])(
441466
"does not let prior non-delivery override a $label automation",
442-
({ enabled, runStatus, expectedStatus }) => {
467+
({ enabled, running, runStatus, expectedStatus }) => {
443468
const job = createBaseJob({
444469
enabled,
445470
state: {
446471
lastRunStatus: runStatus,
447472
lastDeliveryStatus: "not-delivered",
448-
...(expectedStatus === "running" ? { runningAtMs: Date.now() } : {}),
473+
...(running ? { runningAtMs: Date.now() } : {}),
449474
},
450475
});
451476

477+
const list = createRuntimeLogCapture();
478+
printCronList([job], list.runtime);
479+
expectLogsToInclude(list.logs, expectedStatus);
480+
452481
const show = createRuntimeLogCapture();
453482
printCronShow(job, show.runtime);
454483

455484
expectLogsToInclude(show.logs, `status: ${expectedStatus}`);
456485
expect(show.logs.join("\n")).not.toContain("ok (not delivered)");
457486
expect(enrichCronJsonWithStatus(job)).toMatchObject({ status: expectedStatus });
487+
expect(enrichCronJsonWithStatus({ jobs: [job] })).toMatchObject({
488+
jobs: [{ status: expectedStatus }],
489+
});
458490
},
459491
);
460492

‎src/cli/cron-cli/shared.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ export function enrichCronJsonWithStatus(value: unknown): unknown {
170170
}
171171

172172
function computeStatus(job: { enabled?: unknown; state?: unknown }): string {
173-
if (!job.enabled) {
174-
return "disabled";
175-
}
176173
const state = asOptionalRecord(job.state) ?? {};
177174
if (state.runningAtMs) {
178175
return "running";
179176
}
177+
if (!job.enabled) {
178+
return "disabled";
179+
}
180180
return typeof state.lastRunStatus === "string"
181181
? state.lastRunStatus
182182
: typeof state.lastStatus === "string"

0 commit comments

Comments
 (0)