/** * Workflow run manager * * Orchestrates workflow run execution via isolated run executors. * Uses pluggable RunExecutor interface for runtime flexibility. * * Supported runtime: * - ProcessRunExecutor: Child processes for local development and trusted hosts * * Key properties: * - Each workflow runs in isolation (no shared state) * - Supports crash recovery via stalled execution detection * - Runtime-agnostic through RunExecutor abstraction */ import { type WorkflowBackend } from "../backends/types.js"; import type { RunExecutionStatus, RunExecutor } from "./executors/types.js"; export type { RunExecutionInfo, RunExecutionStatus, RunExecutor } from "./executors/types.js"; /** * Configuration for the workflow run manager backed by run executors. */ export interface WorkflowRunManagerConfig { /** Backend for workflow persistence */ backend: WorkflowBackend; /** Run executor used to start isolated workflow processes */ executor: RunExecutor; /** Environment variables to inject into run executions */ env?: Record; /** Poll interval for checking pending workflows (ms) */ pollInterval?: number; /** Maximum concurrent run executions */ maxConcurrentExecutions?: number; /** Run timeout (ms) - kills execution if it exceeds this */ executionTimeout?: number; /** Time after which a run is considered stalled (ms) - for crash recovery */ stalledThreshold?: number; /** Enable debug logging */ debug?: boolean; } /** * Manager status */ export type ManagerStatus = "idle" | "running" | "stopping" | "stopped"; /** * Manager statistics */ export interface ManagerStats { status: ManagerStatus; managerId: string; startedAt?: Date; pollCount: number; executionsCreated: number; executionsCompleted: number; executionsFailed: number; activeExecutions: number; lastPollAt?: Date; lastErrorAt?: Date; lastError?: string; } /** * Internal run execution tracking */ interface TrackedExecution { executionId: string; runId: string; status: RunExecutionStatus; createdAt: Date; /** Consecutive sync cycles this execution was absent from the executor's list. */ missingPolls: number; } /** * Workflow run manager * * Orchestrates workflow execution via pluggable run executors. * Each workflow runs in complete isolation. * * @example Local Process * ```typescript * const executor = new ProcessRunExecutor({ * entrypointPath: "./workflow-run.ts", * }); * * const manager = new WorkflowRunManager({ * backend: redisBackend, * executor, * }); * * manager.start(); * ``` */ export declare class WorkflowRunManager { private config; private status; private pollTimeout?; private activeExecutions; private stats; private managerId; constructor(config: WorkflowRunManagerConfig); /** * Start the workflow run manager. */ start(): Promise; /** * Stop the workflow run manager gracefully. */ stop(): Promise; /** * Get manager statistics */ getStats(): ManagerStats; /** * Get active executions */ getActiveExecutions(): TrackedExecution[]; /** * Get manager ID */ getManagerId(): string; /** * Schedule the next poll */ private scheduleNextPoll; /** * Poll for pending workflows and manage run executions */ private poll; /** * Sync run execution statuses with executor */ private syncRunExecutionStatuses; /** * Create an isolated execution for a workflow run */ private createExecutionForWorkflow; /** * Record an error in stats */ private recordError; } /** * Create a workflow run manager backed by run executors. */ export declare function createWorkflowRunManager(config: WorkflowRunManagerConfig): WorkflowRunManager; //# sourceMappingURL=run-manager.d.ts.map