lidex-mongo
Version: 
MongoDB persistence for Lidex
35 lines (34 loc) • 1.42 kB
TypeScript
import { Collection } from "mongodb";
type Status = "idle" | "running" | "failed" | "finished" | "aborted";
interface Workflow {
    id: string;
    handler: string;
    input: unknown;
    status: Status;
    timeoutAt?: Date;
    failures?: number;
    lastError?: string;
    steps?: {
        [key: string]: unknown;
    };
    naps?: {
        [key: string]: Date;
    };
}
type RunData = Pick<Workflow, "handler" | "input" | "failures">;
export declare class MongoPersistence {
    readonly workflows: Collection<Workflow>;
    constructor(url: string);
    init(): Promise<void>;
    insert(workflowId: string, handler: string, input: unknown): Promise<boolean>;
    claim(now: Date, timeoutAt: Date): Promise<string | undefined>;
    findOutput(workflowId: string, stepId: string): Promise<unknown>;
    findWakeUpAt(workflowId: string, napId: string): Promise<Date | undefined>;
    findRunData(workflowId: string): Promise<RunData | undefined>;
    setAsFinished(workflowId: string): Promise<void>;
    findStatus(workflowId: string): Promise<Status | undefined>;
    updateStatus(workflowId: string, status: Status, timeoutAt: Date, failures: number, lastError: string): Promise<void>;
    updateOutput(workflowId: string, stepId: string, output: unknown, timeoutAt: Date): Promise<void>;
    updateWakeUpAt(workflowId: string, napId: string, wakeUpAt: Date, timeoutAt: Date): Promise<void>;
}
export {};