Skip to content

createEngine(config)

Creates an engine that executes workflows against a storage backend.

typescript
import { createEngine } from 'reflow-ts'

const engine = createEngine({
  storage,
  workflows: [orderWorkflow, emailWorkflow],
})
ParameterTypeDefaultDescription
storageStorageAdapterrequiredBackend for runs and step results
workflowsWorkflow[]requiredWorkflows to register
hooksEngineHooksLifecycle hooks (may be sync or async)
concurrencynumber1Runs processed in parallel per tick
runLeaseDurationMsnumber30000How long a claimed run stays running before another engine may reclaim it
heartbeatIntervalMsnumberlease / 3How often the active worker renews its lease

Returns an Engine. Registering the same workflow name twice throws DuplicateWorkflowError; invalid numeric config throws ConfigError (concurrency must be a positive integer, heartbeatIntervalMs must be smaller than runLeaseDurationMs).

EngineHooks

All hooks are optional and receive an EngineEvent-shaped payload. They may be synchronous or async (awaited). A throwing or rejecting hook never affects engine state.

HookPayload
onRunStart{ runId, workflow }
onStepStart{ runId, workflow, stepName }
onStepComplete{ runId, workflow, stepName, output, attempts }
onRunComplete{ runId, workflow, output }
onRunFailed{ runId, workflow, stepName, error }
onError(error: Error) — background failures (scheduled enqueues, poll cycles)

See Hooks for behavior and Events & Streams for the event shapes.

Released under the MIT License.