@dudousxd/nestjs-durable-core 0.86.0 → 0.86.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +126 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +124 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -4825,6 +4825,12 @@ declare class WorkflowEngine {
|
|
|
4825
4825
|
* releases when its budget runs out.
|
|
4826
4826
|
*/
|
|
4827
4827
|
private readonly executionLeases;
|
|
4828
|
+
/** Runs a caller just locked to execute now, so their turn has nothing to prove and no await to add. */
|
|
4829
|
+
private readonly lockedForTurn;
|
|
4830
|
+
/** Runs this instance holds for a moment and will release, not to execute (see {@link handOffDue}). */
|
|
4831
|
+
private readonly claimsInFlight;
|
|
4832
|
+
/** How many such claims each run has had, so a proof can tell one came and went (see {@link proveOwnLease}). */
|
|
4833
|
+
private readonly claimsMade;
|
|
4828
4834
|
/** Pager hooks for stranded runs (see {@link onStalled}). */
|
|
4829
4835
|
private readonly stalledListeners;
|
|
4830
4836
|
/** Runs already paged about, by id → the `updatedAt` of the paged episode (see {@link sweepStalled}). */
|
|
@@ -4900,6 +4906,14 @@ declare class WorkflowEngine {
|
|
|
4900
4906
|
* one executor either way. Never rejects.
|
|
4901
4907
|
*/
|
|
4902
4908
|
private runFromQueue;
|
|
4909
|
+
private markClaim;
|
|
4910
|
+
/**
|
|
4911
|
+
* Whether this instance holds the run's lease for a turn, from the store and by owner. A renewal can land
|
|
4912
|
+
* on a claim marked after it was sent, and that claim is about to be released, so any claim begun while
|
|
4913
|
+
* the renewal was out, even one already over, leaves it unproved.
|
|
4914
|
+
*/
|
|
4915
|
+
private proveOwnLease;
|
|
4916
|
+
private unmarkClaim;
|
|
4903
4917
|
/**
|
|
4904
4918
|
* Hand due runs (timers, blocked runs due for a fleet re-check) to whichever instance takes them
|
|
4905
4919
|
* off the run queue. Each is claimed first, under its lease, by pushing its `wakeAt` one lease
|
|
@@ -7892,6 +7906,22 @@ declare function withSingletonTracked(tags: string[] | undefined): string[];
|
|
|
7892
7906
|
* window is the head of the FIFO, admitted next anyway); with a larger limit it can only delay one.
|
|
7893
7907
|
*/
|
|
7894
7908
|
declare function legacySingletonHolders(active: WorkflowRun[], runId: string, limit: number): WorkflowRun[];
|
|
7909
|
+
/**
|
|
7910
|
+
* The size of one locking statement of {@link singletonClaimantIds}. Keep a store's chunks in the
|
|
7911
|
+
* order the database listed the ids: every claim then takes shared rows in one global order.
|
|
7912
|
+
*/
|
|
7913
|
+
declare const SINGLETON_LOCK_CHUNK = 500;
|
|
7914
|
+
/**
|
|
7915
|
+
* The runs a claim must lock: the active runs sharing its exact tag, in the order given. Admission
|
|
7916
|
+
* reads no other run, so claims on different keys need not wait for each other. Read them BEFORE the
|
|
7917
|
+
* admission transaction opens: on MySQL's REPEATABLE READ an earlier plain read would freeze the
|
|
7918
|
+
* snapshot the admission decision reads. A run that a later claim adds is still safe: that claim
|
|
7919
|
+
* started after this one's run existed, so its own lock set holds this run and the two serialize.
|
|
7920
|
+
*/
|
|
7921
|
+
declare function singletonClaimantIds(rows: readonly {
|
|
7922
|
+
id: string;
|
|
7923
|
+
tags?: unknown;
|
|
7924
|
+
}[], tag: string): string[];
|
|
7895
7925
|
/** Call only inside a store's atomic admission transaction/critical section. */
|
|
7896
7926
|
declare function singletonAdmissionTags(runs: WorkflowRun[], runId: string, tag: string, workflow: string, limit: number): string[] | null;
|
|
7897
7927
|
/** Terminal runs release admission, including when later resumed directly rather than requeued. */
|
|
@@ -7904,4 +7934,4 @@ declare function singletonAdmissionDenialPatch(runs: WorkflowRun[], runId: strin
|
|
|
7904
7934
|
updatedAt: Date;
|
|
7905
7935
|
} | undefined;
|
|
7906
7936
|
|
|
7907
|
-
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, REMOTE_EVENT, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, WorkflowNotRegistered, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isRemoteEvent, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, markRemoteEvent, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
|
|
7937
|
+
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, REMOTE_EVENT, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_LOCK_CHUNK, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, WorkflowNotRegistered, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isRemoteEvent, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, markRemoteEvent, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, singletonClaimantIds, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
|
package/dist/index.d.ts
CHANGED
|
@@ -4825,6 +4825,12 @@ declare class WorkflowEngine {
|
|
|
4825
4825
|
* releases when its budget runs out.
|
|
4826
4826
|
*/
|
|
4827
4827
|
private readonly executionLeases;
|
|
4828
|
+
/** Runs a caller just locked to execute now, so their turn has nothing to prove and no await to add. */
|
|
4829
|
+
private readonly lockedForTurn;
|
|
4830
|
+
/** Runs this instance holds for a moment and will release, not to execute (see {@link handOffDue}). */
|
|
4831
|
+
private readonly claimsInFlight;
|
|
4832
|
+
/** How many such claims each run has had, so a proof can tell one came and went (see {@link proveOwnLease}). */
|
|
4833
|
+
private readonly claimsMade;
|
|
4828
4834
|
/** Pager hooks for stranded runs (see {@link onStalled}). */
|
|
4829
4835
|
private readonly stalledListeners;
|
|
4830
4836
|
/** Runs already paged about, by id → the `updatedAt` of the paged episode (see {@link sweepStalled}). */
|
|
@@ -4900,6 +4906,14 @@ declare class WorkflowEngine {
|
|
|
4900
4906
|
* one executor either way. Never rejects.
|
|
4901
4907
|
*/
|
|
4902
4908
|
private runFromQueue;
|
|
4909
|
+
private markClaim;
|
|
4910
|
+
/**
|
|
4911
|
+
* Whether this instance holds the run's lease for a turn, from the store and by owner. A renewal can land
|
|
4912
|
+
* on a claim marked after it was sent, and that claim is about to be released, so any claim begun while
|
|
4913
|
+
* the renewal was out, even one already over, leaves it unproved.
|
|
4914
|
+
*/
|
|
4915
|
+
private proveOwnLease;
|
|
4916
|
+
private unmarkClaim;
|
|
4903
4917
|
/**
|
|
4904
4918
|
* Hand due runs (timers, blocked runs due for a fleet re-check) to whichever instance takes them
|
|
4905
4919
|
* off the run queue. Each is claimed first, under its lease, by pushing its `wakeAt` one lease
|
|
@@ -7892,6 +7906,22 @@ declare function withSingletonTracked(tags: string[] | undefined): string[];
|
|
|
7892
7906
|
* window is the head of the FIFO, admitted next anyway); with a larger limit it can only delay one.
|
|
7893
7907
|
*/
|
|
7894
7908
|
declare function legacySingletonHolders(active: WorkflowRun[], runId: string, limit: number): WorkflowRun[];
|
|
7909
|
+
/**
|
|
7910
|
+
* The size of one locking statement of {@link singletonClaimantIds}. Keep a store's chunks in the
|
|
7911
|
+
* order the database listed the ids: every claim then takes shared rows in one global order.
|
|
7912
|
+
*/
|
|
7913
|
+
declare const SINGLETON_LOCK_CHUNK = 500;
|
|
7914
|
+
/**
|
|
7915
|
+
* The runs a claim must lock: the active runs sharing its exact tag, in the order given. Admission
|
|
7916
|
+
* reads no other run, so claims on different keys need not wait for each other. Read them BEFORE the
|
|
7917
|
+
* admission transaction opens: on MySQL's REPEATABLE READ an earlier plain read would freeze the
|
|
7918
|
+
* snapshot the admission decision reads. A run that a later claim adds is still safe: that claim
|
|
7919
|
+
* started after this one's run existed, so its own lock set holds this run and the two serialize.
|
|
7920
|
+
*/
|
|
7921
|
+
declare function singletonClaimantIds(rows: readonly {
|
|
7922
|
+
id: string;
|
|
7923
|
+
tags?: unknown;
|
|
7924
|
+
}[], tag: string): string[];
|
|
7895
7925
|
/** Call only inside a store's atomic admission transaction/critical section. */
|
|
7896
7926
|
declare function singletonAdmissionTags(runs: WorkflowRun[], runId: string, tag: string, workflow: string, limit: number): string[] | null;
|
|
7897
7927
|
/** Terminal runs release admission, including when later resumed directly rather than requeued. */
|
|
@@ -7904,4 +7934,4 @@ declare function singletonAdmissionDenialPatch(runs: WorkflowRun[], runId: strin
|
|
|
7904
7934
|
updatedAt: Date;
|
|
7905
7935
|
} | undefined;
|
|
7906
7936
|
|
|
7907
|
-
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, REMOTE_EVENT, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, WorkflowNotRegistered, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isRemoteEvent, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, markRemoteEvent, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
|
|
7937
|
+
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, REMOTE_EVENT, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_LOCK_CHUNK, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, WorkflowNotRegistered, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isRemoteEvent, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, markRemoteEvent, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, singletonClaimantIds, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
|
package/dist/index.js
CHANGED
|
@@ -3268,6 +3268,11 @@ function legacySingletonHolders(active, runId, limit) {
|
|
|
3268
3268
|
return scanned.filter((run) => run.id !== runId && !run.tags?.includes(SINGLETON_ADMITTED_TAG) && (!run.tags?.includes(SINGLETON_TRACKED_TAG) || window.has(run.id)));
|
|
3269
3269
|
}
|
|
3270
3270
|
__name(legacySingletonHolders, "legacySingletonHolders");
|
|
3271
|
+
var SINGLETON_LOCK_CHUNK = 500;
|
|
3272
|
+
function singletonClaimantIds(rows, tag) {
|
|
3273
|
+
return rows.filter((row) => Array.isArray(row.tags) && row.tags.includes(tag)).map((row) => row.id);
|
|
3274
|
+
}
|
|
3275
|
+
__name(singletonClaimantIds, "singletonClaimantIds");
|
|
3271
3276
|
function singletonAdmissionTags(runs, runId, tag, workflow, limit) {
|
|
3272
3277
|
if (!Number.isInteger(limit) || limit < 1) throw new Error("singleton limit must be a positive integer");
|
|
3273
3278
|
const active = runs.filter((run) => run.workflow === workflow && SINGLETON_ACTIVE_STATUSES.includes(run.status) && run.tags?.includes(tag));
|
|
@@ -3312,6 +3317,41 @@ __name(singletonAdmissionDenialPatch, "singletonAdmissionDenialPatch");
|
|
|
3312
3317
|
// src/singleton-gate.ts
|
|
3313
3318
|
var SINGLETON_RETRY_MS = 1e3;
|
|
3314
3319
|
var SINGLETON_RETRY_JITTER_MS = 250;
|
|
3320
|
+
var ADMISSION_ATTEMPTS = 3;
|
|
3321
|
+
var ADMISSION_BACKOFF_MS = 40;
|
|
3322
|
+
var LOCK_CONFLICT_CODES = /* @__PURE__ */ new Set([
|
|
3323
|
+
"40P01",
|
|
3324
|
+
"40001",
|
|
3325
|
+
"ER_LOCK_DEADLOCK",
|
|
3326
|
+
"1213",
|
|
3327
|
+
"P2034",
|
|
3328
|
+
"TransactionWriteConflict"
|
|
3329
|
+
]);
|
|
3330
|
+
function isLockConflict(error2) {
|
|
3331
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3332
|
+
const pending = [
|
|
3333
|
+
error2
|
|
3334
|
+
];
|
|
3335
|
+
while (pending.length > 0) {
|
|
3336
|
+
const current = pending.pop();
|
|
3337
|
+
if (typeof current !== "object" || current === null || seen.has(current)) continue;
|
|
3338
|
+
seen.add(current);
|
|
3339
|
+
const e = current;
|
|
3340
|
+
for (const code of [
|
|
3341
|
+
e.code,
|
|
3342
|
+
e.errno,
|
|
3343
|
+
e.sqlState,
|
|
3344
|
+
e.sqlstate,
|
|
3345
|
+
e.originalCode,
|
|
3346
|
+
e.kind
|
|
3347
|
+
]) {
|
|
3348
|
+
if (LOCK_CONFLICT_CODES.has(String(code))) return true;
|
|
3349
|
+
}
|
|
3350
|
+
pending.push(e.cause, e.driverError, e.originalError, e.meta, e.driverAdapterError);
|
|
3351
|
+
}
|
|
3352
|
+
return false;
|
|
3353
|
+
}
|
|
3354
|
+
__name(isLockConflict, "isLockConflict");
|
|
3315
3355
|
var SingletonGate = class {
|
|
3316
3356
|
static {
|
|
3317
3357
|
__name(this, "SingletonGate");
|
|
@@ -3353,7 +3393,7 @@ var SingletonGate = class {
|
|
|
3353
3393
|
if (!this.deps.store.tryAdmitSingleton) {
|
|
3354
3394
|
throw new Error("Singleton workflows require StateStore.tryAdmitSingleton for atomic durable admission");
|
|
3355
3395
|
}
|
|
3356
|
-
const admitted = await this.
|
|
3396
|
+
const admitted = await this.claim(run, cfg);
|
|
3357
3397
|
if (admitted && !run.tags?.includes(SINGLETON_ADMITTED_TAG)) {
|
|
3358
3398
|
run.tags = [
|
|
3359
3399
|
...(run.tags ?? []).filter((tag) => tag !== SINGLETON_TRACKED_TAG),
|
|
@@ -3363,6 +3403,26 @@ var SingletonGate = class {
|
|
|
3363
3403
|
return admitted;
|
|
3364
3404
|
}
|
|
3365
3405
|
/**
|
|
3406
|
+
* One claim, retried when the database aborts it as a lock conflict. A conflict that outlasts the
|
|
3407
|
+
* retries answers "not admitted", so the engine releases this turn's lease, instead of stranding
|
|
3408
|
+
* the run until the lease lapses. It writes nothing to the run: this turn's lease may have lapsed
|
|
3409
|
+
* during the claim, and another instance may now hold the run, its slot and newer tags. A later
|
|
3410
|
+
* sweep re-drives the run: recovery once it is unleased, or its timer if it is parked.
|
|
3411
|
+
*/
|
|
3412
|
+
async claim(run, cfg) {
|
|
3413
|
+
const admit = this.deps.store.tryAdmitSingleton;
|
|
3414
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
3415
|
+
try {
|
|
3416
|
+
return await admit.call(this.deps.store, run.id, this.tag(cfg, run.input), run.workflow, cfg.limit ?? 1, this.retryWakeAt());
|
|
3417
|
+
} catch (error2) {
|
|
3418
|
+
if (!isLockConflict(error2)) throw error2;
|
|
3419
|
+
if (attempt >= ADMISSION_ATTEMPTS) return false;
|
|
3420
|
+
const backoff = ADMISSION_BACKOFF_MS * attempt * (0.5 + Math.random());
|
|
3421
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
/**
|
|
3366
3426
|
* Notify-on-release: a singleton run settled (freeing a slot), so dispatch the oldest gated
|
|
3367
3427
|
* (`suspended` + same tag) waiters now instead of waiting for their ~1s retry timer. Each re-checks
|
|
3368
3428
|
* admission in the executor and runs only if it actually wins a slot, so FIFO/race-free guarantees
|
|
@@ -5139,6 +5199,12 @@ var WorkflowEngine = class {
|
|
|
5139
5199
|
* releases when its budget runs out.
|
|
5140
5200
|
*/
|
|
5141
5201
|
executionLeases = /* @__PURE__ */ new Map();
|
|
5202
|
+
/** Runs a caller just locked to execute now, so their turn has nothing to prove and no await to add. */
|
|
5203
|
+
lockedForTurn = /* @__PURE__ */ new Set();
|
|
5204
|
+
/** Runs this instance holds for a moment and will release, not to execute (see {@link handOffDue}). */
|
|
5205
|
+
claimsInFlight = /* @__PURE__ */ new Map();
|
|
5206
|
+
/** How many such claims each run has had, so a proof can tell one came and went (see {@link proveOwnLease}). */
|
|
5207
|
+
claimsMade = /* @__PURE__ */ new Map();
|
|
5142
5208
|
/** Pager hooks for stranded runs (see {@link onStalled}). */
|
|
5143
5209
|
stalledListeners = /* @__PURE__ */ new Set();
|
|
5144
5210
|
/** Runs already paged about, by id → the `updatedAt` of the paged episode (see {@link sweepStalled}). */
|
|
@@ -5482,6 +5548,27 @@ var WorkflowEngine = class {
|
|
|
5482
5548
|
console.error(`[nestjs-durable] could not run queued run ${runId}:`, error2);
|
|
5483
5549
|
}
|
|
5484
5550
|
}
|
|
5551
|
+
markClaim(runId) {
|
|
5552
|
+
this.claimsInFlight.set(runId, (this.claimsInFlight.get(runId) ?? 0) + 1);
|
|
5553
|
+
if (this.claimsMade.size >= 4096) this.claimsMade.clear();
|
|
5554
|
+
this.claimsMade.set(runId, (this.claimsMade.get(runId) ?? 0) + 1);
|
|
5555
|
+
}
|
|
5556
|
+
/**
|
|
5557
|
+
* Whether this instance holds the run's lease for a turn, from the store and by owner. A renewal can land
|
|
5558
|
+
* on a claim marked after it was sent, and that claim is about to be released, so any claim begun while
|
|
5559
|
+
* the renewal was out, even one already over, leaves it unproved.
|
|
5560
|
+
*/
|
|
5561
|
+
async proveOwnLease(runId, nowMs) {
|
|
5562
|
+
if (this.claimsInFlight.has(runId)) return false;
|
|
5563
|
+
const before = this.claimsMade.get(runId);
|
|
5564
|
+
const renewed = await this.store.renewRunLock(runId, this.instanceId, nowMs + this.leaseMs);
|
|
5565
|
+
return renewed && !this.claimsInFlight.has(runId) && this.claimsMade.get(runId) === before;
|
|
5566
|
+
}
|
|
5567
|
+
unmarkClaim(runId) {
|
|
5568
|
+
const left = (this.claimsInFlight.get(runId) ?? 1) - 1;
|
|
5569
|
+
if (left > 0) this.claimsInFlight.set(runId, left);
|
|
5570
|
+
else this.claimsInFlight.delete(runId);
|
|
5571
|
+
}
|
|
5485
5572
|
/**
|
|
5486
5573
|
* Hand due runs (timers, blocked runs due for a fleet re-check) to whichever instance takes them
|
|
5487
5574
|
* off the run queue. Each is claimed first, under its lease, by pushing its `wakeAt` one lease
|
|
@@ -5493,29 +5580,34 @@ var WorkflowEngine = class {
|
|
|
5493
5580
|
const claimed = [];
|
|
5494
5581
|
for (const run of runs) {
|
|
5495
5582
|
if (this.draining) break;
|
|
5496
|
-
|
|
5497
|
-
continue;
|
|
5498
|
-
}
|
|
5499
|
-
if (!this.isRegisteredHere(run) && !await this.canResolveWorkflow(run)) {
|
|
5500
|
-
const result = await this.settleUnregistered(run, nowMs);
|
|
5501
|
-
if (result) settled?.set(run.id, result);
|
|
5502
|
-
else if (result === void 0) this.logUnregisteredSkip(run);
|
|
5503
|
-
continue;
|
|
5504
|
-
}
|
|
5583
|
+
this.markClaim(run.id);
|
|
5505
5584
|
try {
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
}
|
|
5509
|
-
if (this.
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5585
|
+
if (!await this.store.tryLockRun(run.id, this.instanceId, nowMs + this.leaseMs, nowMs)) {
|
|
5586
|
+
continue;
|
|
5587
|
+
}
|
|
5588
|
+
if (!this.isRegisteredHere(run) && !await this.canResolveWorkflow(run)) {
|
|
5589
|
+
const result = await this.settleUnregistered(run, nowMs);
|
|
5590
|
+
if (result) settled?.set(run.id, result);
|
|
5591
|
+
else if (result === void 0) this.logUnregisteredSkip(run);
|
|
5592
|
+
continue;
|
|
5593
|
+
}
|
|
5594
|
+
try {
|
|
5595
|
+
const patch = {
|
|
5596
|
+
wakeAt: nowMs + this.leaseMs
|
|
5597
|
+
};
|
|
5598
|
+
if (this.store.updateRunIf) {
|
|
5599
|
+
if (await this.store.updateRunIf(run.id, [
|
|
5600
|
+
run.status
|
|
5601
|
+
], patch)) claimed.push(run);
|
|
5602
|
+
} else {
|
|
5603
|
+
await this.store.updateRun(run.id, patch);
|
|
5604
|
+
claimed.push(run);
|
|
5605
|
+
}
|
|
5606
|
+
} finally {
|
|
5607
|
+
await this.store.releaseRunLock(run.id, this.instanceId);
|
|
5516
5608
|
}
|
|
5517
5609
|
} finally {
|
|
5518
|
-
|
|
5610
|
+
this.unmarkClaim(run.id);
|
|
5519
5611
|
}
|
|
5520
5612
|
}
|
|
5521
5613
|
try {
|
|
@@ -6970,7 +7062,8 @@ var WorkflowEngine = class {
|
|
|
6970
7062
|
const nowMs = this.clock();
|
|
6971
7063
|
const acquired = await this.store.tryLockRun(runId, this.instanceId, nowMs + this.leaseMs, nowMs);
|
|
6972
7064
|
if (!acquired) return null;
|
|
6973
|
-
|
|
7065
|
+
this.lockedForTurn.add(runId);
|
|
7066
|
+
return this.resumeImplicit(runId).finally(() => this.lockedForTurn.delete(runId)).catch(async (err) => {
|
|
6974
7067
|
if (err instanceof NamespaceMismatch) return null;
|
|
6975
7068
|
if (err instanceof WorkflowNotRegistered) {
|
|
6976
7069
|
const run = await this.store.getRun(runId);
|
|
@@ -7254,6 +7347,7 @@ var WorkflowEngine = class {
|
|
|
7254
7347
|
}
|
|
7255
7348
|
try {
|
|
7256
7349
|
const settled = onLocked ? await onLocked(run) : void 0;
|
|
7350
|
+
if (!settled) this.lockedForTurn.add(run.id);
|
|
7257
7351
|
results.push(settled ?? await this.resumeImplicit(run.id));
|
|
7258
7352
|
} catch (error2) {
|
|
7259
7353
|
if (error2 instanceof WorkflowNotRegistered) {
|
|
@@ -7262,6 +7356,8 @@ var WorkflowEngine = class {
|
|
|
7262
7356
|
if (settled !== void 0) continue;
|
|
7263
7357
|
}
|
|
7264
7358
|
console.error(`[nestjs-durable] could not resume run ${run.id} (${run.workflow}@${run.workflowVersion}); leaving it for another instance:`, error2);
|
|
7359
|
+
} finally {
|
|
7360
|
+
this.lockedForTurn.delete(run.id);
|
|
7265
7361
|
}
|
|
7266
7362
|
}
|
|
7267
7363
|
return results;
|
|
@@ -8277,7 +8373,7 @@ var WorkflowEngine = class {
|
|
|
8277
8373
|
const current = await this.store.getRun(run.id);
|
|
8278
8374
|
if (!this.isFenced(run.id)) {
|
|
8279
8375
|
this.handOffLease(run.id);
|
|
8280
|
-
await this.store.releaseRunLock(run.id);
|
|
8376
|
+
await this.store.releaseRunLock(run.id, this.instanceId);
|
|
8281
8377
|
}
|
|
8282
8378
|
if (!current) throw new Error(`run ${run.id} was deleted during singleton admission`);
|
|
8283
8379
|
if (current.status === "suspended") {
|
|
@@ -8303,7 +8399,9 @@ var WorkflowEngine = class {
|
|
|
8303
8399
|
fans: /* @__PURE__ */ new Map()
|
|
8304
8400
|
};
|
|
8305
8401
|
this.wakeReasons.delete(run.id);
|
|
8306
|
-
|
|
8402
|
+
const lockedForTurn = this.lockedForTurn.delete(run.id);
|
|
8403
|
+
const reentered = run.lockedBy === this.instanceId && (run.lockedUntil ?? 0) > lockNow && (lockedForTurn || await this.proveOwnLease(run.id, lockNow));
|
|
8404
|
+
if (!reentered) {
|
|
8307
8405
|
if (!await this.store.tryLockRun(run.id, this.instanceId, lockNow + this.leaseMs, lockNow)) {
|
|
8308
8406
|
if (reason.generic) {
|
|
8309
8407
|
if (!this.genericWakeRequested.has(run.id)) {
|
|
@@ -13003,6 +13101,7 @@ export {
|
|
|
13003
13101
|
RunGateway,
|
|
13004
13102
|
SINGLETON_ACTIVE_STATUSES,
|
|
13005
13103
|
SINGLETON_ADMITTED_TAG,
|
|
13104
|
+
SINGLETON_LOCK_CHUNK,
|
|
13006
13105
|
SINGLETON_RESERVED_TAGS,
|
|
13007
13106
|
SINGLETON_TRACKED_TAG,
|
|
13008
13107
|
STATE_STORE,
|
|
@@ -13136,6 +13235,7 @@ export {
|
|
|
13136
13235
|
signTenantToken,
|
|
13137
13236
|
singletonAdmissionDenialPatch,
|
|
13138
13237
|
singletonAdmissionTags,
|
|
13238
|
+
singletonClaimantIds,
|
|
13139
13239
|
sqlComparator,
|
|
13140
13240
|
stepConfigOf,
|
|
13141
13241
|
stepId,
|