UNPKG

durabull

Version:

A durable workflow engine built on top of BullMQ and Redis

99 lines (98 loc) 3.42 kB
/** * WorkflowStub - interface for controlling and executing workflows (Durable Mode Only) */ import { Workflow } from './Workflow'; import { WorkflowStatus } from './runtime/history'; import { WorkflowExecutionContext } from './runtime/context'; export { WorkflowStatus } from './runtime/history'; export { WorkflowWaitError, WorkflowContinueAsNewError } from './errors'; export interface WorkflowDispatchOptions { id?: string; queue?: string; queueContext?: Record<string, unknown>; } /** * WorkflowHandle - interface for interacting with a workflow instance */ export declare class WorkflowHandle<TArgs extends any[] = any[], TResult = any> { private workflowId; private workflowName; constructor(workflowId: string, workflowName: string); id(): string; start(...args: TArgs): Promise<void>; status(): Promise<WorkflowStatus>; output(): Promise<TResult>; /** * Get query method proxy - queries access workflow state from storage */ query<T extends Record<string, (...args: any[]) => any>>(WorkflowClass: new () => Workflow<any, any>): T; } /** * WorkflowStub - Static methods for workflow control */ export declare class WorkflowStub { /** * Create a new workflow handle */ static make<T extends Workflow<TArgs, TResult>, TArgs extends any[] = any[], TResult = any>(workflowClassOrName: (new () => T) | string, options?: WorkflowDispatchOptions): Promise<WorkflowHandle<TArgs, TResult>>; /** * Load an existing workflow by ID */ static load<TArgs extends any[] = any[], TResult = any>(id: string): Promise<WorkflowHandle<TArgs, TResult>>; /** * Send a signal to a workflow */ static sendSignal(workflowId: string, signalName: string, payload: any[]): Promise<void>; /** * Get current time (replay-safe for workflows) */ static now(): Date; /** * Sleep for a duration (workflow timer) */ static timer(durationSeconds: number | string): Promise<void>; /** * Wait for a condition to become true */ static await(predicate: () => boolean): Promise<void>; /** * Wait for condition with timeout */ static awaitWithTimeout(durationSeconds: number | string, predicate: () => boolean): Promise<boolean>; /** * Continue as new workflow */ static continueAsNew(...args: any[]): Promise<never>; /** * Execute side effect (non-deterministic code) */ static sideEffect<T>(fn: () => T | Promise<T>): Promise<T>; /** * Execute child workflow */ static child<TResult = any>(workflowClassOrName: (new () => Workflow<any, any>) | string, ...args: any[]): Promise<TResult>; /** * Get workflow execution context (internal use) */ static _getContext(): WorkflowExecutionContext | null; /** * Generate a deterministic ID for a side effect */ static _generateSideEffectId(): string; /** * Generate a deterministic ID for a child workflow */ static _generateChildWorkflowId(): string; /** * Generate a deterministic ID for an activity */ static _generateActivityId(): string; /** * Generate a deterministic ID for a timer */ static _generateTimerId(): string; /** * Run code in workflow context (internal use by workers) */ static _run<T>(ctx: WorkflowExecutionContext, fn: () => T): T; }