@penkov/tasks_queue
Version:
A lightweight PostgreSQL-backed task queue system with scheduling, retries, backoff strategies, and priority handling. Designed for efficiency and observability in modern Node.js applications.
70 lines (69 loc) • 2.65 kB
TypeScript
import { Option } from "scats";
import { ActiveChildState } from "./active-child-state.js";
/**
* Persisted payload envelope for stateful parent-child workflows.
*
* The envelope separates orchestration state owned by the workflow runtime from
* user business payload and optional active child metadata.
*/
export declare class MultiStepPayload<TUserPayload extends object = Record<string, unknown>> {
/**
* Currently active child task metadata, if the parent is blocked waiting for it.
*/
readonly activeChild: Option<ActiveChildState>;
/**
* Workflow-owned orchestration state.
*/
readonly workflowPayload: Record<string, any>;
/**
* Domain-specific business payload owned by the workflow implementation.
*/
readonly userPayload: TUserPayload;
/**
* Create a fresh workflow envelope from user business payload only.
*
* This is the default entrypoint for scheduling a new multi-step parent task:
* - no active child yet
* - empty workflow-owned orchestration state
* - provided user payload as workflow business input
*
* @param userPayload domain-specific business payload
* @returns envelope ready to be serialized and scheduled
*/
static forUserPayload<TUserPayload extends object>(userPayload: TUserPayload): MultiStepPayload<TUserPayload>;
constructor(
/**
* Currently active child task metadata, if the parent is blocked waiting for it.
*/
activeChild: Option<ActiveChildState>,
/**
* Workflow-owned orchestration state.
*/
workflowPayload: Record<string, any>,
/**
* Domain-specific business payload owned by the workflow implementation.
*/
userPayload: TUserPayload);
/**
* Create a shallow copy with selected envelope parts replaced.
*
* @param o replacement envelope parts
* @returns copied payload envelope with overrides applied
*/
copy(o: Partial<MultiStepPayload<TUserPayload>>): MultiStepPayload<TUserPayload>;
/**
* Serialize the envelope into plain JSON suitable for task payload persistence.
*
* @returns plain object ready for {@link ScheduleTaskDetails.payload}
*/
get toJson(): object;
/**
* Deserialize workflow envelope from plain JSON payload.
*
* For backward compatibility this also reads legacy `activeChildId` payloads.
*
* @param j serialized workflow payload
* @returns parsed multi-step envelope with empty defaults when sections are missing
*/
static fromJson<TUserPayload extends object>(j: unknown): MultiStepPayload<TUserPayload>;
}