/** * Defines workflow engine services and an in-memory implementation. * * `WorkflowEngine` registers workflow handlers, runs executions, polls results, * resumes suspended runs, executes activities, stores durable deferred results, * and schedules durable clocks. `WorkflowInstance` holds the runtime state for * one workflow run. The in-memory layer is useful for tests and local * development. * * @stability unstable * @since 4.0.0 */ import * as Cause from "../Cause.ts"; import * as Context from "../Context.ts"; import * as Effect from "../Effect.ts"; import * as Exit from "../Exit.ts"; import * as Latch from "../Latch.ts"; import * as Layer from "../Layer.ts"; import * as Option from "../Option.ts"; import * as Schedule from "../Schedule.ts"; import * as Schema from "../Schema.ts"; import * as Scope from "../Scope.ts"; import type * as Activity from "./Activity.ts"; import type { DurableClock } from "./DurableClock.ts"; import type * as DurableDeferred from "./DurableDeferred.ts"; import * as Workflow from "./Workflow.ts"; declare const WorkflowEngine_base: Context.ServiceClass(workflow: Workflow.Workflow, execute: (payload: Payload["Type"], executionId: string) => Effect.Effect) => Effect.Effect | Scope.Scope> | Payload["DecodingServices"] | Payload["EncodingServices"] | Success["DecodingServices"] | Success["EncodingServices"] | Error["DecodingServices"] | Error["EncodingServices"]>; /** * Execute a registered workflow. * * **Details** * * Unless `discard` is set, a caller outside any workflow waits for the * result. While the execution is suspended, the caller retries on * `suspendedRetrySchedule`; engines that observe the final result wake it * sooner. `ClusterWorkflowEngine` does so only for callers on the runner * that owns the execution. * * `detached: true` requires `discard: true` and skips parent completion * wakes and interruption linkage. Otherwise, it is a defect. */ readonly execute: (workflow: Workflow.Workflow, options: { readonly executionId: string; readonly payload: Payload["Type"]; readonly discard?: Discard | undefined; readonly detached?: boolean | undefined; readonly suspendedRetrySchedule?: Schedule.Schedule | undefined; }) => Effect.Effect; /** * Poll the current status of a registered workflow execution. */ readonly poll: (workflow: Workflow.Workflow, executionId: string) => Effect.Effect>, never, Success["DecodingServices"] | Error["DecodingServices"]>; /** * Interrupt a registered workflow. */ readonly interrupt: (workflow: Workflow.Any, executionId: string) => Effect.Effect; /** * Interrupts a registered workflow unsafely, potentially ignoring * compensation finalizers and orphaning child workflows. */ readonly interruptUnsafe: (workflow: Workflow.Any, executionId: string) => Effect.Effect; /** * Resume a registered workflow. */ readonly resume: (workflow: Workflow.Any, executionId: string) => Effect.Effect; /** * Execute an activity from a workflow. */ readonly activityExecute: (activity: Activity.Activity, attempt: number) => Effect.Effect, never, Success["DecodingServices"] | Error["DecodingServices"] | R | WorkflowInstance>; /** * Try to retrieve the result of an DurableDeferred */ readonly deferredResult: (deferred: DurableDeferred.DurableDeferred) => Effect.Effect>, never, WorkflowInstance>; /** * Set the result of a DurableDeferred, and then resume any waiting * workflows. */ readonly deferredDone: (deferred: DurableDeferred.DurableDeferred, options: { readonly workflowName: string; readonly executionId: string; readonly deferredName: string; readonly exit: Exit.Exit; }) => Effect.Effect; /** * Schedule a wake up for a DurableClock */ readonly scheduleClock: (workflow: Workflow.Any, options: { readonly executionId: string; readonly clock: DurableClock; }) => Effect.Effect; }>; /** * Service that represents workflow runtimes, responsible for registering and * executing workflows and coordinating activities, durable deferreds, * interrupts, resumes, and clocks. * * @stability unstable * @category services * @since 4.0.0 */ export declare class WorkflowEngine extends WorkflowEngine_base { } declare const WorkflowInstance_base: Context.ServiceClass | undefined; /** * Whether this workflow or an activity hit `SuspendOnFailure`, excluding * inherited child failures. */ failed: boolean; /** * Deferred names this run waits on, counted per live wait; their * completions preempt the run. */ readonly awaitedDeferreds: Map; /** Deferred names this run completed itself; their completions need not wake it. */ readonly completedDeferreds: Set; readonly activityState: { count: number; readonly latch: Latch.Latch; }; }>; /** * Service that contains workflow runtime state for one execution. * * **When to use** * * Use to read or update workflow execution, suspension, interruption, * lifetime, failure, and activity coordination state inside workflow engine * internals. * * **Details** * * The service stores the execution ID, workflow definition, long-lived scope, * suspension and interruption flags, the stored failure cause, and activity * coordination state for a single workflow run. * * @stability unstable * @category services * @since 4.0.0 */ export declare class WorkflowInstance extends WorkflowInstance_base { static initial(workflow: Workflow.Any, executionId: string, options?: { readonly scope?: Scope.Closeable | undefined; /** * Awaited deferred names shared with the run this instance belongs to. * An activity instance registers its durable waits there so the run * can be woken once it suspends, without those waits preempting it. */ readonly awaitedDeferreds?: Map | undefined; }): WorkflowInstance["Service"]; } /** * Tracks live workflow runs so deferred completions can wake them. * * @stability unstable * @category models * @since 4.0.0 */ export interface DeferredState { /** Tracks and provides a run until it completes or suspends. */ readonly trackRun: (instance: WorkflowInstance["Service"], effect: Effect.Effect) => Effect.Effect>; /** Preempts a run parked on the completed deferred. */ readonly deferredDone: (executionId: string, name: string) => Effect.Effect; } /** * Creates deferred state shared by workflow engines. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const makeDeferredState: () => DeferredState; /** * Low-level workflow engine contract that works with encoded payloads and * results before `makeUnsafe` adds typed schema decoding and encoding. * * @stability unstable * @category services * @since 4.0.0 */ export interface Encoded { readonly register: (workflow: Workflow.Any, execute: (payload: object, executionId: string) => Effect.Effect) => Effect.Effect; readonly execute: (workflow: Workflow.Any, options: { readonly executionId: string; readonly payload: object; readonly discard: Discard; readonly parent?: WorkflowInstance["Service"] | undefined; /** Skip parent completion wakes and interruption linkage. */ readonly detached?: boolean | undefined; }) => Effect.Effect>; readonly poll: (workflow: Workflow.Any, executionId: string) => Effect.Effect>>; readonly interrupt: (workflow: Workflow.Any, executionId: string) => Effect.Effect; readonly interruptUnsafe: (workflow: Workflow.Any, executionId: string) => Effect.Effect; readonly resume: (workflow: Workflow.Any, executionId: string) => Effect.Effect; /** * Waits until a suspended execution has a result other than `Suspended`. * * **Gotchas** * * External callers race this with their `suspendedRetrySchedule`, so it may * never complete when the engine cannot observe the result. Completing while * the execution is still suspended skips the sleep and spends a step of that * schedule. A hook that keeps completing early makes the caller spin. */ readonly awaitComplete?: (workflow: Workflow.Any, executionId: string) => Effect.Effect; readonly activityExecute: (activity: Activity.Any, attempt: number) => Effect.Effect, never, WorkflowInstance>; readonly deferredResult: (deferred: DurableDeferred.Any) => Effect.Effect>, never, WorkflowInstance>; readonly deferredDone: (options: { readonly workflowName: string; readonly executionId: string; readonly deferredName: string; readonly exit: Exit.Exit; }) => Effect.Effect; readonly scheduleClock: (workflow: Workflow.Any, options: { readonly executionId: string; readonly clock: DurableClock; }) => Effect.Effect; } /** * Builds a typed `WorkflowEngine` service from a low-level encoded * implementation. * * **When to use** * * Use when wiring a trusted low-level workflow engine implementation into the * typed `WorkflowEngine` service. * * **Gotchas** * * The implementation must correctly persist, resume, and encode workflow state. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const makeUnsafe: (options: Encoded) => WorkflowEngine["Service"]; /** * Layer that provides an in-memory `WorkflowEngine`. * * **When to use** * * Use to run tests and local development workflows where durability is not * needed. * * **Gotchas** * * This layer keeps state only in memory and is not suitable for production * workflows that require durability. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerMemory: Layer.Layer; export {}; //# sourceMappingURL=WorkflowEngine.d.ts.map