mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
4d9052929b
Cron executions now write full-fidelity task_runs rows (detail_json column, store-key scoped) and cron.runs/CLI/task-maintenance read from the ledger; legacy cron_run_logs dual-write stays as a revert safety net. Existing history auto-imports at first state-DB open (verified against a production DB copy: 2750/2750 rows, byte-identical parity, idempotent). Startup crash recovery restores finished runs from finalized ledger rows instead of reporting synthetic interruptions. Part 1 of 2 for #106041.
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
// Defines managed task-flow registry records and parser helpers.
|
|
import type { DeliveryContext } from "../utils/delivery-context.types.js";
|
|
import type { JsonValue, TaskNotifyPolicy } from "./task-registry.types.js";
|
|
|
|
export type { JsonValue } from "./task-registry.types.js";
|
|
|
|
export type TaskFlowSyncMode = "task_mirrored" | "managed";
|
|
|
|
/** Lifecycle status for multi-step task flows. */
|
|
export type TaskFlowStatus =
|
|
| "queued"
|
|
| "running"
|
|
| "waiting"
|
|
| "blocked"
|
|
| "succeeded"
|
|
| "failed"
|
|
| "cancelled"
|
|
| "lost";
|
|
|
|
const TASK_FLOW_SYNC_MODES = new Set<TaskFlowSyncMode>(["task_mirrored", "managed"]);
|
|
const TASK_FLOW_STATUSES = new Set<TaskFlowStatus>([
|
|
"queued",
|
|
"running",
|
|
"waiting",
|
|
"blocked",
|
|
"succeeded",
|
|
"failed",
|
|
"cancelled",
|
|
"lost",
|
|
]);
|
|
|
|
function parsePersistedFlowValue<T extends string>(
|
|
value: unknown,
|
|
values: ReadonlySet<T>,
|
|
label: string,
|
|
): T {
|
|
if (typeof value === "string" && values.has(value as T)) {
|
|
return value as T;
|
|
}
|
|
throw new Error(`Invalid persisted task flow ${label}: ${JSON.stringify(value)}`);
|
|
}
|
|
|
|
export function parseOptionalTaskFlowSyncMode(value: unknown): TaskFlowSyncMode | undefined {
|
|
if (value == null || value === "") {
|
|
return undefined;
|
|
}
|
|
return parsePersistedFlowValue(value, TASK_FLOW_SYNC_MODES, "sync mode");
|
|
}
|
|
|
|
export function parseTaskFlowStatus(value: unknown): TaskFlowStatus {
|
|
return parsePersistedFlowValue(value, TASK_FLOW_STATUSES, "status");
|
|
}
|
|
|
|
export type TaskFlowRecord = {
|
|
flowId: string;
|
|
syncMode: TaskFlowSyncMode;
|
|
ownerKey: string;
|
|
requesterOrigin?: DeliveryContext;
|
|
controllerId?: string;
|
|
revision: number;
|
|
status: TaskFlowStatus;
|
|
notifyPolicy: TaskNotifyPolicy;
|
|
goal: string;
|
|
currentStep?: string;
|
|
blockedTaskId?: string;
|
|
blockedSummary?: string;
|
|
stateJson?: JsonValue;
|
|
waitJson?: JsonValue;
|
|
cancelRequestedAt?: number;
|
|
createdAt: number;
|
|
updatedAt: number;
|
|
endedAt?: number;
|
|
};
|