Skip to content

@codesoul-co/hypha-core / modules/execution-store/durable-execution-worker

Using this module

Use the Durable execution worker module for persisting and reading data at this boundary. It exports 3 classes, 2 interfaces.

Import from the package entrypoint

ts
import {
  DurableExecutionWorker,
  ExecutionWorkerLeaseLostError,
  ExecutionWorkerReconciliationRequiredError,
} from '@codesoul-co/hypha-core';

import type {
  DurableExecutionRecoveryReconciler,
  DurableExecutionWorkerOptions,
} from '@codesoul-co/hypha-core';

Usage patterns

  • Use the 2 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 3 classes as constructable runtime implementations. Each symbol entry lists its constructor and public methods.

Public exports

SymbolKindSignatureDescription
DurableExecutionWorkerclassnew DurableExecutionWorker(options: DurableExecutionWorkerOptions): DurableExecutionWorkerProvider-neutral lease/fencing coordinator for durable Execution workers. Provider execution remains behind the Execution activity boundary. This class only claims persisted work and supplies fenced renew/commit/release operations so Server composition does not reimplement Store semantics.
ExecutionWorkerLeaseLostErrorclassnew ExecutionWorkerLeaseLostError(executionId: string, workerId: string): ExecutionWorkerLeaseLostErrorExecution Worker Lease Lost Error class with 9 public constructor or member entries; its exact declarations are listed below.
ExecutionWorkerReconciliationRequiredErrorclassnew ExecutionWorkerReconciliationRequiredError(executionId: string, reason: string): ExecutionWorkerReconciliationRequiredErrorExecution Worker Reconciliation Required Error class with 10 public constructor or member entries; its exact declarations are listed below.
DurableExecutionRecoveryReconcilerinterfaceinterface DurableExecutionRecoveryReconcilerDurable Execution Recovery Reconciler interface with 1 public fields or methods.
DurableExecutionWorkerOptionsinterfaceinterface DurableExecutionWorkerOptionsDurable Execution Worker Options interface with 7 public fields or methods.

DurableExecutionWorker

Provider-neutral lease/fencing coordinator for durable Execution workers. Provider execution remains behind the Execution activity boundary. This class only claims persisted work and supplies fenced renew/commit/release operations so Server composition does not reimplement Store semantics.

Declaration

text
export declare class DurableExecutionWorker {
    constructor(options: DurableExecutionWorkerOptions);
    startClaiming(): void;
    stopClaiming(): void;
    claimNext(): Promise<ExecutionRecord | null>;
    renew(recordValue: ExecutionRecord): Promise<ExecutionRecord>;
    commit(recordValue: ExecutionRecord, resultValue: CommandExecutionResult): Promise<ExecutionRecord>;
    checkpointTerminalReceipt(recordValue: ExecutionRecord, receiptValue: ExecutionReceipt): Promise<ExecutionRecord>;
    release(recordValue: ExecutionRecord, reason?: string): Promise<ExecutionRecord>;
}

Public members

MemberKindSignatureDescription
checkpointTerminalReceiptmethodcheckpointTerminalReceipt(recordValue: ExecutionRecord, receiptValue: ExecutionReceipt): Promise<ExecutionRecord>Public method; parameters and return type are shown in the signature.
claimNextmethodclaimNext(): Promise<ExecutionRecord | null>Public method; parameters and return type are shown in the signature.
commitmethodcommit(recordValue: ExecutionRecord, resultValue: CommandExecutionResult): Promise<ExecutionRecord>Public method; parameters and return type are shown in the signature.
constructorconstructor(options: DurableExecutionWorkerOptions): DurableExecutionWorkerCreates an instance of this class.
releasemethodrelease(recordValue: ExecutionRecord, reason?: string): Promise<ExecutionRecord>Public method; parameters and return type are shown in the signature.
renewmethodrenew(recordValue: ExecutionRecord): Promise<ExecutionRecord>Public method; parameters and return type are shown in the signature.
startClaimingmethodstartClaiming(): voidPublic method; parameters and return type are shown in the signature.
stopClaimingmethodstopClaiming(): voidPublic method; parameters and return type are shown in the signature.

ExecutionWorkerLeaseLostError

Execution Worker Lease Lost Error class with 9 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class ExecutionWorkerLeaseLostError extends Error {
    readonly code = "EXECUTION_WORKER_LEASE_LOST";
    constructor(executionId: string, workerId: string);
}

Public members

MemberKindSignatureDescription
causepropertycause?: unknownPublic property; its type, readonly modifier and optionality are shown in the signature.
codepropertyreadonly code: "EXECUTION_WORKER_LEASE_LOST"Public property; its type, readonly modifier and optionality are shown in the signature.
constructorconstructor(executionId: string, workerId: string): ExecutionWorkerLeaseLostErrorCreates an instance of this class.
messagepropertymessage: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
namepropertyname: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stackpropertystack?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
static captureStackTracemethodstatic captureStackTrace(targetObject: object, constructorOpt?: Function): voidCreates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called. js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}. The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace. The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance: js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a();
static prepareStackTracemethodstatic prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): anyPublic method; parameters and return type are shown in the signature.
static stackTraceLimitpropertystatic stackTraceLimit: numberThe Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

ExecutionWorkerReconciliationRequiredError

Execution Worker Reconciliation Required Error class with 10 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class ExecutionWorkerReconciliationRequiredError extends Error {
    readonly code = "EXECUTION_WORKER_RECONCILIATION_REQUIRED";
    readonly reason: string;
    constructor(executionId: string, reason: string);
}

Public members

MemberKindSignatureDescription
causepropertycause?: unknownPublic property; its type, readonly modifier and optionality are shown in the signature.
codepropertyreadonly code: "EXECUTION_WORKER_RECONCILIATION_REQUIRED"Public property; its type, readonly modifier and optionality are shown in the signature.
constructorconstructor(executionId: string, reason: string): ExecutionWorkerReconciliationRequiredErrorCreates an instance of this class.
messagepropertymessage: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
namepropertyname: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reasonpropertyreadonly reason: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stackpropertystack?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
static captureStackTracemethodstatic captureStackTrace(targetObject: object, constructorOpt?: Function): voidCreates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called. js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}. The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace. The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance: js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a();
static prepareStackTracemethodstatic prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): anyPublic method; parameters and return type are shown in the signature.
static stackTraceLimitpropertystatic stackTraceLimit: numberThe Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

DurableExecutionRecoveryReconciler

Durable Execution Recovery Reconciler interface with 1 public fields or methods.

Declaration

text
export interface DurableExecutionRecoveryReconciler {
    assess(record: ExecutionRecord): Promise<ExecutionRecoveryAssessment>;
}

Contract members

MemberKindSignatureDescription
assessmethodassess(record: ExecutionRecord): Promise<ExecutionRecoveryAssessment>Public method; parameters and return type are shown in the signature.

DurableExecutionWorkerOptions

Durable Execution Worker Options interface with 7 public fields or methods.

Declaration

text
export interface DurableExecutionWorkerOptions {
    store: ExecutionStore;
    workerId: string;
    recoveryReconciler?: DurableExecutionRecoveryReconciler;
    leaseTtlMs?: number;
    claimBatchSize?: number;
    now?: () => string;
    leaseId?: (executionId: string, workerId: string) => string;
}

Contract members

MemberKindSignatureDescription
claimBatchSizepropertyclaimBatchSize?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
leaseIdmethodleaseId?(executionId: string, workerId: string): stringPublic method; parameters and return type are shown in the signature.
leaseTtlMspropertyleaseTtlMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.
recoveryReconcilerpropertyrecoveryReconciler?: DurableExecutionRecoveryReconcilerPublic property; its type, readonly modifier and optionality are shown in the signature.
storepropertystore: ExecutionStorePublic property; its type, readonly modifier and optionality are shown in the signature.
workerIdpropertyworkerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.