Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(frontend): the schedule belongs with the task helpers

zchpeterfa1ae4d454c2
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx
index 5e32a3ea76..dcbb5880dc 100644
--- a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx
+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx
@@ -14,7 +14,10 @@ import {
} from "@/types/proto-es/v1/rollout_service_pb";
import type { User } from "@/types/proto-es/v1/user_service_pb";
import { databaseForTask } from "@/utils";
-import { isReleaseBasedTask } from "@/utils/v1/issue/rollout";
+import {
+ isReleaseBasedTask,
+ scheduledRunTimeMs,
+} from "@/utils/v1/issue/rollout";
import { isRerunnableTaskStatus } from "../lifecycle/frontierStage";
import { PlanDetailRollbackSheet } from "../PlanDetailRollbackSheet";
import {
@@ -24,7 +27,6 @@ import {
import { DeployTaskBody } from "./DeployTaskBody";
import { DeployTaskHeader } from "./DeployTaskHeader";
import { DeployTaskRunHistorySheet } from "./DeployTaskRunHistorySheet";
-import { scheduledRunTimeMs } from "./scheduledRunTime";
import { useDeployTaskActions } from "./taskActions";
import { useDeployTaskStatement } from "./useDeployTaskStatement";
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.test.ts b/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.test.ts
deleted file mode 100644
index 146b0eb495..0000000000
--- a/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.test.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-// @vitest-environment node
-
-import { create } from "@bufbuild/protobuf";
-import { timestampFromMs } from "@bufbuild/protobuf/wkt";
-import { describe, expect, test } from "vitest";
-import {
- Task_Status,
- TaskSchema,
-} from "@/types/proto-es/v1/rollout_service_pb";
-import { scheduledRunTimeMs } from "./scheduledRunTime";
-
-const RUN_AT_MS = 1_772_452_800_000;
-
-const task = (status: Task_Status, runTimeMs?: number) =>
- create(TaskSchema, {
- status,
- runTime: runTimeMs === undefined ? undefined : timestampFromMs(runTimeMs),
- });
-
-describe("scheduledRunTimeMs", () => {
- test("gives the instant a waiting task is due to run", () => {
- expect(scheduledRunTimeMs(task(Task_Status.PENDING, RUN_AT_MS))).toBe(
- RUN_AT_MS
- );
- });
-
- test("gives nothing for a waiting task with no time set", () => {
- // Zero is an instant, and an instant reads as a schedule: a task waiting
- // for nothing in particular must not show one.
- expect(scheduledRunTimeMs(task(Task_Status.PENDING))).toBeUndefined();
- });
-
- test.each([
- ["running", Task_Status.RUNNING],
- ["done", Task_Status.DONE],
- ["failed", Task_Status.FAILED],
- ["skipped", Task_Status.SKIPPED],
- ["canceled", Task_Status.CANCELED],
- ])("gives nothing for a %s task that carries one", (_name, status) => {
- expect(scheduledRunTimeMs(task(status, RUN_AT_MS))).toBeUndefined();
- });
-});
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.ts b/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.ts
deleted file mode 100644
index 7dcad2ad33..0000000000
--- a/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { getTimeForPbTimestampProtoEs } from "@/types";
-import type { Task } from "@/types/proto-es/v1/rollout_service_pb";
-import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
-
-/**
- * When a task is due to run, or nothing at all: a schedule belongs to a task
- * still waiting for it, and a task that has started or finished is described
- * by its run, not by the time it was once meant to begin.
- */
-export function scheduledRunTimeMs(task: Task): number | undefined {
- return task.status === Task_Status.PENDING
- ? getTimeForPbTimestampProtoEs(task.runTime)
- : undefined;
-}
diff --git a/frontend/src/utils/v1/issue/rollout.test.ts b/frontend/src/utils/v1/issue/rollout.test.ts
index 9d10bc7436..a066a1c00f 100644
--- a/frontend/src/utils/v1/issue/rollout.test.ts
+++ b/frontend/src/utils/v1/issue/rollout.test.ts
@@ -1,5 +1,6 @@
// @vitest-environment node
import { create } from "@bufbuild/protobuf";
+import { timestampFromMs } from "@bufbuild/protobuf/wkt";
import { describe, expect, test } from "vitest";
import { Plan_TaskStatusCountSchema } from "@/types/proto-es/v1/plan_service_pb";
import {
@@ -13,6 +14,7 @@ import {
getStageStatus,
getStageStatusFromCounts,
isTaskActivelyTransitioning,
+ scheduledRunTimeMs,
} from "./rollout";
const stage = (...statuses: Task_Status[]) =>
@@ -165,3 +167,39 @@ describe("isTaskActivelyTransitioning", () => {
}
});
});
+
+const RUN_AT_MS = 1_772_452_800_000;
+
+const scheduledTask = (status: Task_Status, runTimeMs?: number) =>
+ create(TaskSchema, {
+ status,
+ runTime: runTimeMs === undefined ? undefined : timestampFromMs(runTimeMs),
+ });
+
+describe("scheduledRunTimeMs", () => {
+ test("gives the instant a waiting task is due to run", () => {
+ expect(
+ scheduledRunTimeMs(scheduledTask(Task_Status.PENDING, RUN_AT_MS))
+ ).toBe(RUN_AT_MS);
+ });
+
+ test("gives nothing for a waiting task with no time set", () => {
+ // Such a task is due now, not scheduled -- the reading rollout.ts already
+ // takes of an absent runTime.
+ expect(
+ scheduledRunTimeMs(scheduledTask(Task_Status.PENDING))
+ ).toBeUndefined();
+ });
+
+ test.each([
+ ["running", Task_Status.RUNNING],
+ ["done", Task_Status.DONE],
+ ["failed", Task_Status.FAILED],
+ ["skipped", Task_Status.SKIPPED],
+ ["canceled", Task_Status.CANCELED],
+ ])("gives nothing for a %s task that carries one", (_name, status) => {
+ expect(
+ scheduledRunTimeMs(scheduledTask(status, RUN_AT_MS))
+ ).toBeUndefined();
+ });
+});
diff --git a/frontend/src/utils/v1/issue/rollout.ts b/frontend/src/utils/v1/issue/rollout.ts
index 7fcbd98961..3a1fdb1154 100644
--- a/frontend/src/utils/v1/issue/rollout.ts
+++ b/frontend/src/utils/v1/issue/rollout.ts
@@ -155,6 +155,18 @@ export const isTaskActivelyTransitioning = (
return !task.runTime || getTimeForPbTimestampProtoEs(task.runTime) <= nowMs;
};
+/**
+ * When a task is due to run, or nothing at all: a schedule belongs to a task
+ * still waiting for it, and a task that has started or finished is described
+ * by its run, not by the time it was once meant to begin. A task with no
+ * runTime is due now rather than scheduled, which is the same reading
+ * `isTaskActivelyTransitioning` above takes of the field.
+ */
+export const scheduledRunTimeMs = (task: Task): number | undefined =>
+ task.status === Task_Status.PENDING
+ ? getTimeForPbTimestampProtoEs(task.runTime)
+ : undefined;
+
// Task_Status ONLY. Task_Status and TaskRun_Status share names but their
// numeric values are offset by one (Task_Status.PENDING === 2 ===
// TaskRun_Status.RUNNING), so one switch cannot serve both enums — a task