Skip to content

Commit f498727

Browse files
authored
fix(cron): show running status for active paused jobs (#129339)
1 parent 3be7baa commit f498727

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
@@ -474,27 +474,59 @@ describe("printCronList", () => {
474474
);
475475

476476
it.each([
477-
{ label: "disabled", enabled: false, runStatus: "ok" as const, expectedStatus: "disabled" },
478-
{ label: "running", enabled: true, runStatus: "ok" as const, expectedStatus: "running" },
479-
{ label: "failed", enabled: true, runStatus: "error" as const, expectedStatus: "error" },
477+
{
478+
label: "disabled",
479+
enabled: false,
480+
running: false,
481+
runStatus: "ok" as const,
482+
expectedStatus: "disabled",
483+
},
484+
{
485+
label: "running",
486+
enabled: true,
487+
running: true,
488+
runStatus: "ok" as const,
489+
expectedStatus: "running",
490+
},
491+
{
492+
label: "paused but force-running",
493+
enabled: false,
494+
running: true,
495+
runStatus: "ok" as const,
496+
expectedStatus: "running",
497+
},
498+
{
499+
label: "failed",
500+
enabled: true,
501+
running: false,
502+
runStatus: "error" as const,
503+
expectedStatus: "error",
504+
},
480505
])(
481506
"does not let prior non-delivery override a $label automation",
482-
({ enabled, runStatus, expectedStatus }) => {
507+
({ enabled, running, runStatus, expectedStatus }) => {
483508
const job = createBaseJob({
484509
enabled,
485510
state: {
486511
lastRunStatus: runStatus,
487512
lastDeliveryStatus: "not-delivered",
488-
...(expectedStatus === "running" ? { runningAtMs: Date.now() } : {}),
513+
...(running ? { runningAtMs: Date.now() } : {}),
489514
},
490515
});
491516

517+
const list = createRuntimeLogCapture();
518+
printCronList([job], list.runtime);
519+
expectLogsToInclude(list.logs, expectedStatus);
520+
492521
const show = createRuntimeLogCapture();
493522
printCronShow(job, show.runtime);
494523

495524
expectLogsToInclude(show.logs, `status: ${expectedStatus}`);
496525
expect(show.logs.join("\n")).not.toContain("ok (not delivered)");
497526
expect(enrichCronJsonWithStatus(job)).toMatchObject({ status: expectedStatus });
527+
expect(enrichCronJsonWithStatus({ jobs: [job] })).toMatchObject({
528+
jobs: [{ status: expectedStatus }],
529+
});
498530
},
499531
);
500532

‎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)