UNPKG

durabull

Version:

A durable workflow engine built on top of BullMQ and Redis

28 lines (27 loc) 942 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replayWorkflow = void 0; const storage_1 = require("./storage"); const ReplayEngine_1 = require("./ReplayEngine"); async function replayWorkflow(workflowId, WorkflowClass, record) { const storage = (0, storage_1.getStorage)(); if (!record) { const loadedRecord = await storage.readRecord(workflowId); if (!loadedRecord) { throw new Error(`Workflow ${workflowId} not found`); } record = loadedRecord; } const history = (await storage.readHistory(workflowId)) || { events: [], cursor: 0 }; const workflow = new WorkflowClass(); const signals = await storage.listSignals(workflowId); return ReplayEngine_1.ReplayEngine.run({ workflowId, workflow, record, history, signals, isResume: true, }); } exports.replayWorkflow = replayWorkflow;