@nagi-js/core 0.1.1-rc.16 → 0.1.1-rc.17
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.d.ts +42 -1
- package/dist/index.js +134 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -482,6 +482,7 @@ interface WorkerConfig {
|
|
|
482
482
|
readonly concurrency?: number;
|
|
483
483
|
readonly pollIntervalMs?: Millis;
|
|
484
484
|
readonly signal?: AbortSignal;
|
|
485
|
+
readonly timerSweepIntervalMs?: Millis;
|
|
485
486
|
}
|
|
486
487
|
interface WorkerRunOnceOpts {
|
|
487
488
|
readonly maxSteps?: number;
|
|
@@ -516,6 +517,12 @@ type SettleSignalResult = {
|
|
|
516
517
|
} | {
|
|
517
518
|
readonly tag: "noop";
|
|
518
519
|
};
|
|
520
|
+
interface TimedOutSignal {
|
|
521
|
+
readonly runId: RunId$1;
|
|
522
|
+
readonly stepId: StepId;
|
|
523
|
+
readonly attempt: AttemptNumber;
|
|
524
|
+
readonly fireAt: Date;
|
|
525
|
+
}
|
|
519
526
|
interface Store {
|
|
520
527
|
appendFact(runId: RunId$1, fact: Fact): Promise<void>;
|
|
521
528
|
loadRunState(runId: RunId$1): Promise<RunState>;
|
|
@@ -555,6 +562,11 @@ interface Store {
|
|
|
555
562
|
readonly queue: Queue;
|
|
556
563
|
readonly limit?: number;
|
|
557
564
|
}): Promise<readonly ReapedLease[]>;
|
|
565
|
+
upsertTimer(runId: RunId$1, stepId: StepId, fireAt: Date): Promise<void>;
|
|
566
|
+
sweepSignalTimeouts(args: {
|
|
567
|
+
readonly now: Date;
|
|
568
|
+
readonly limit?: number;
|
|
569
|
+
}): Promise<readonly TimedOutSignal[]>;
|
|
558
570
|
settleStep(runId: RunId$1, stepId: StepId, fact: StepCompletedFact | StepFailedFact): Promise<void>;
|
|
559
571
|
recordOnce(runId: RunId$1, stepId: StepId, scope: string, value: Json): Promise<void>;
|
|
560
572
|
getOnce(runId: RunId$1, stepId: StepId, scope: string): Promise<Json | null>;
|
|
@@ -894,6 +906,16 @@ declare class NagiCanceledError extends Error {
|
|
|
894
906
|
readonly concurrencyKey: string;
|
|
895
907
|
});
|
|
896
908
|
}
|
|
909
|
+
declare class NagiSignalTimeoutError extends Error {
|
|
910
|
+
readonly runId: RunId$1;
|
|
911
|
+
readonly stepId: string;
|
|
912
|
+
readonly fireAt: Date;
|
|
913
|
+
constructor({ runId, stepId, fireAt, }: {
|
|
914
|
+
readonly runId: RunId$1;
|
|
915
|
+
readonly stepId: string;
|
|
916
|
+
readonly fireAt: Date;
|
|
917
|
+
});
|
|
918
|
+
}
|
|
897
919
|
declare class NagiFlowSnapshotGoneError extends Error {
|
|
898
920
|
readonly runId: RunId$1;
|
|
899
921
|
readonly flowId: string;
|
|
@@ -942,6 +964,7 @@ declare class InMemoryStore implements Store, StreamTransport {
|
|
|
942
964
|
private readonly childrenByParent;
|
|
943
965
|
private readonly summaries;
|
|
944
966
|
private readonly streamHub;
|
|
967
|
+
private readonly signalTimers;
|
|
945
968
|
private readonly leaseMs;
|
|
946
969
|
constructor(opts?: InMemoryStoreOpts);
|
|
947
970
|
appendFact(runId: RunId$1, fact: Fact): Promise<void>;
|
|
@@ -985,6 +1008,11 @@ declare class InMemoryStore implements Store, StreamTransport {
|
|
|
985
1008
|
readonly signalName?: string;
|
|
986
1009
|
};
|
|
987
1010
|
}): Promise<SettleSignalResult>;
|
|
1011
|
+
upsertTimer(runId: RunId$1, stepId: StepId, fireAt: Date): Promise<void>;
|
|
1012
|
+
sweepSignalTimeouts(args: {
|
|
1013
|
+
readonly now: Date;
|
|
1014
|
+
readonly limit?: number;
|
|
1015
|
+
}): Promise<readonly TimedOutSignal[]>;
|
|
988
1016
|
recordOnce(runId: RunId$1, stepId: StepId, scope: string, value: Json): Promise<void>;
|
|
989
1017
|
getOnce(runId: RunId$1, stepId: StepId, scope: string): Promise<Json | null>;
|
|
990
1018
|
runStep<T extends Json>(runId: RunId$1, _stepId: StepId, _attempt: AttemptNumber, body: (tx: Tx) => Promise<{
|
|
@@ -1145,6 +1173,19 @@ declare function decideSignal(args: {
|
|
|
1145
1173
|
readonly signalName?: string;
|
|
1146
1174
|
} | undefined;
|
|
1147
1175
|
}): SignalDecision;
|
|
1176
|
+
type TimeoutDecision = {
|
|
1177
|
+
readonly kind: "noop";
|
|
1178
|
+
} | {
|
|
1179
|
+
readonly kind: "fail";
|
|
1180
|
+
readonly attempt: AttemptNumber;
|
|
1181
|
+
readonly fact: StepFailedFact;
|
|
1182
|
+
};
|
|
1183
|
+
declare function decideTimeout(args: {
|
|
1184
|
+
readonly runState: RunState;
|
|
1185
|
+
readonly stepId: StepId;
|
|
1186
|
+
readonly fireAt: Date;
|
|
1187
|
+
readonly at: Date;
|
|
1188
|
+
}): TimeoutDecision;
|
|
1148
1189
|
|
|
1149
1190
|
declare class NagiAbortError extends Error {
|
|
1150
1191
|
readonly runId: RunId$1;
|
|
@@ -1152,4 +1193,4 @@ declare class NagiAbortError extends Error {
|
|
|
1152
1193
|
constructor(runId: RunId$1, kind: "run" | "step");
|
|
1153
1194
|
}
|
|
1154
1195
|
|
|
1155
|
-
export { type Anomaly, type AttemptNumber, type BackoffStrategy, type Builder, type CancelArgs, type CanonicalDag, type CanonicalMatchArm, type CanonicalRetryPolicy, type CanonicalSchema, type CanonicalStep, type ClaimToken, type Clock, type ConcurrencyMode, DEFAULT_REAPER_INTERVAL_MS, type Fact, type FactKind, type Flow, type FlowCanceledByConcurrencyFact, type FlowCanceledByOperatorFact, type FlowCanceledExplicitlyFact, type FlowCanceledFact, type FlowCompleteEvent, type FlowCompletedFact, type FlowConcurrency, type FlowConfig, type FlowErrorEvent, type FlowEvent, type FlowFailedFact, type FlowHooks, type FlowIdOf, type FlowInput, type FlowOutput, type FlowRefUpdatedFact, type FlowStartEvent, type FlowStartedFact, type GlobalFact, InMemoryClock, InMemoryQueue, InMemoryStore, InMemoryTrigger, type InferSchemaInput, type InferSchemaOutput, type Json, type LeaseReapedFact, type LogEntry, type LogLevel, type Logger, type MatchArm, type MatchArmGuard, type MatchArmOtherwise, type MatchArmOutput, type MatchArmSelectedFact, type MatchArmShape, type MatchGuardConfig, type Millis, NagiAbortError, NagiCanceledError, NagiConcurrencyConflictError, type NagiConfig, NagiFlowSnapshotGoneError, type NagiRunConfig, NagiRuntimeError, NagiSnapshotDriftError, NagiValidationError, type NeedRef, type NeedsMap, type NeedsOutputs, type OnceRecordedFact, type Operator, type OperatorAuditOpts, type Optional, type ParentLink, type ParentRef, type PrunableStatus, type PruneOpts, type PruneResult, type QueryRunsOpts, type QueryRunsResult, type QueryRunsWhere, type Queue, type QueueDequeueOpts, type QueueEnqueueOpts, type QueueMessage, type ReapedLease, type ReaperDecision, type Register, type ReplayMode, type ReplayOpts, type Resolved, type ResolvedConcurrency, type ResolvedNeeds, type RetryPolicy, type RunCancelCause, type RunDescription, RunId, type RunPhase, type RunState, type RunStatus, type RunSummary, type RunView, type RuntimeHandle, type SerializedError, type SettleSignalResult, type SignalBufferedFact, type SignalConfig, type SignalDecision, type SignalReceivedEvent, type SignalReceivedFact, type SignalSentEvent, type SignalSentFact, type SkipReason, type SnapshotChangedEdge, type SnapshotChangedField, type SnapshotDiff, StandardSchemaV1, type StartOpts, type StartStagedOpts, type StartStagedResult, type Step, type StepAbortRequestedFact, type StepCancelCause, type StepCanceledFact, type StepCompleteEvent, type StepCompletedFact, type StepCtx, type StepErrorEvent, type StepEvent, type StepFailedFact, type StepId, type StepKind, type StepMap, type StepOutput, type StepResetFact, type StepRetriedFact, type StepRetryEvent, type StepRunStatus, type StepSkippedFact, type StepStartEvent, type StepStartedFact, type StepState, type StepStatus, type StepView, type Store, type StreamEvent, type StreamTransport, type StreamingStepCtx, type StreamingTaskConfig, type StringKeyOf, type SubflowConfig, type SubflowStepOutput, type TaskConfig, type Trigger, type Tx, type Wf, type Worker, type WorkerConfig, type WorkerRunOnceOpts, type WorkerRunResult, type WorkerRunUntilEmptyOpts, attemptOf, canonicalize, decideExpiredLeaseAction, decideSignal, diffSnapshots, errorOf, fingerprintFlows, flow, isStepTerminal, isTerminalRun, nagi, optional, outputOf, foldRun as projectRunState, resolvedOf, runStatusOf, sha256Canonical, stepStateOf, stepStatusOf, unwrap };
|
|
1196
|
+
export { type Anomaly, type AttemptNumber, type BackoffStrategy, type Builder, type CancelArgs, type CanonicalDag, type CanonicalMatchArm, type CanonicalRetryPolicy, type CanonicalSchema, type CanonicalStep, type ClaimToken, type Clock, type ConcurrencyMode, DEFAULT_REAPER_INTERVAL_MS, type Fact, type FactKind, type Flow, type FlowCanceledByConcurrencyFact, type FlowCanceledByOperatorFact, type FlowCanceledExplicitlyFact, type FlowCanceledFact, type FlowCompleteEvent, type FlowCompletedFact, type FlowConcurrency, type FlowConfig, type FlowErrorEvent, type FlowEvent, type FlowFailedFact, type FlowHooks, type FlowIdOf, type FlowInput, type FlowOutput, type FlowRefUpdatedFact, type FlowStartEvent, type FlowStartedFact, type GlobalFact, InMemoryClock, InMemoryQueue, InMemoryStore, InMemoryTrigger, type InferSchemaInput, type InferSchemaOutput, type Json, type LeaseReapedFact, type LogEntry, type LogLevel, type Logger, type MatchArm, type MatchArmGuard, type MatchArmOtherwise, type MatchArmOutput, type MatchArmSelectedFact, type MatchArmShape, type MatchGuardConfig, type Millis, NagiAbortError, NagiCanceledError, NagiConcurrencyConflictError, type NagiConfig, NagiFlowSnapshotGoneError, type NagiRunConfig, NagiRuntimeError, NagiSignalTimeoutError, NagiSnapshotDriftError, NagiValidationError, type NeedRef, type NeedsMap, type NeedsOutputs, type OnceRecordedFact, type Operator, type OperatorAuditOpts, type Optional, type ParentLink, type ParentRef, type PrunableStatus, type PruneOpts, type PruneResult, type QueryRunsOpts, type QueryRunsResult, type QueryRunsWhere, type Queue, type QueueDequeueOpts, type QueueEnqueueOpts, type QueueMessage, type ReapedLease, type ReaperDecision, type Register, type ReplayMode, type ReplayOpts, type Resolved, type ResolvedConcurrency, type ResolvedNeeds, type RetryPolicy, type RunCancelCause, type RunDescription, RunId, type RunPhase, type RunState, type RunStatus, type RunSummary, type RunView, type RuntimeHandle, type SerializedError, type SettleSignalResult, type SignalBufferedFact, type SignalConfig, type SignalDecision, type SignalReceivedEvent, type SignalReceivedFact, type SignalSentEvent, type SignalSentFact, type SkipReason, type SnapshotChangedEdge, type SnapshotChangedField, type SnapshotDiff, StandardSchemaV1, type StartOpts, type StartStagedOpts, type StartStagedResult, type Step, type StepAbortRequestedFact, type StepCancelCause, type StepCanceledFact, type StepCompleteEvent, type StepCompletedFact, type StepCtx, type StepErrorEvent, type StepEvent, type StepFailedFact, type StepId, type StepKind, type StepMap, type StepOutput, type StepResetFact, type StepRetriedFact, type StepRetryEvent, type StepRunStatus, type StepSkippedFact, type StepStartEvent, type StepStartedFact, type StepState, type StepStatus, type StepView, type Store, type StreamEvent, type StreamTransport, type StreamingStepCtx, type StreamingTaskConfig, type StringKeyOf, type SubflowConfig, type SubflowStepOutput, type TaskConfig, type TimedOutSignal, type TimeoutDecision, type Trigger, type Tx, type Wf, type Worker, type WorkerConfig, type WorkerRunOnceOpts, type WorkerRunResult, type WorkerRunUntilEmptyOpts, attemptOf, canonicalize, decideExpiredLeaseAction, decideSignal, decideTimeout, diffSnapshots, errorOf, fingerprintFlows, flow, isStepTerminal, isTerminalRun, nagi, optional, outputOf, foldRun as projectRunState, resolvedOf, runStatusOf, sha256Canonical, stepStateOf, stepStatusOf, unwrap };
|
package/dist/index.js
CHANGED
|
@@ -856,6 +856,24 @@ var NagiCanceledError = class extends Error {
|
|
|
856
856
|
};
|
|
857
857
|
}
|
|
858
858
|
};
|
|
859
|
+
var NagiSignalTimeoutError = class extends Error {
|
|
860
|
+
runId;
|
|
861
|
+
stepId;
|
|
862
|
+
fireAt;
|
|
863
|
+
constructor({
|
|
864
|
+
runId,
|
|
865
|
+
stepId,
|
|
866
|
+
fireAt
|
|
867
|
+
}) {
|
|
868
|
+
super(
|
|
869
|
+
`Signal step "${stepId}" (run ${runId}) timed out \u2014 no signal arrived before its deadline ${fireAt.toISOString()}.`
|
|
870
|
+
);
|
|
871
|
+
this.name = "NagiSignalTimeoutError";
|
|
872
|
+
this.runId = runId;
|
|
873
|
+
this.stepId = stepId;
|
|
874
|
+
this.fireAt = fireAt;
|
|
875
|
+
}
|
|
876
|
+
};
|
|
859
877
|
var NagiFlowSnapshotGoneError = class extends Error {
|
|
860
878
|
runId;
|
|
861
879
|
flowId;
|
|
@@ -1149,6 +1167,19 @@ function decideSignal(args) {
|
|
|
1149
1167
|
result: { tag: "buffered" }
|
|
1150
1168
|
};
|
|
1151
1169
|
}
|
|
1170
|
+
function decideTimeout(args) {
|
|
1171
|
+
const { runState, stepId, fireAt, at } = args;
|
|
1172
|
+
const step = stepStateOf(runState, stepId);
|
|
1173
|
+
if (step.tag !== "awaitingSignal") return { kind: "noop" };
|
|
1174
|
+
const error = serializeError(
|
|
1175
|
+
new NagiSignalTimeoutError({ runId: runState.runId, stepId, fireAt })
|
|
1176
|
+
);
|
|
1177
|
+
return {
|
|
1178
|
+
kind: "fail",
|
|
1179
|
+
attempt: step.attempt,
|
|
1180
|
+
fact: Facts.stepFailed(runState.runId, stepId, step.attempt, error, at)
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1152
1183
|
function makeSignals(deps) {
|
|
1153
1184
|
const { dispatcher, store, clock, registry, hooks, flowHooks, emitLog } = deps;
|
|
1154
1185
|
async function signal(runId, signalName, payload) {
|
|
@@ -1405,6 +1436,10 @@ var InMemoryStore = class {
|
|
|
1405
1436
|
childrenByParent = /* @__PURE__ */ new Map();
|
|
1406
1437
|
summaries = /* @__PURE__ */ new Map();
|
|
1407
1438
|
streamHub = new InMemoryStreamHub();
|
|
1439
|
+
// Durable signal-timeout deadlines, keyed `${runId}::${stepId}` → fire_at.
|
|
1440
|
+
// The Postgres analogue is the nagi.timer table; this is its in-memory twin
|
|
1441
|
+
// (distinct from the InMemoryClock's setTimeout-based scheduler timers).
|
|
1442
|
+
signalTimers = /* @__PURE__ */ new Map();
|
|
1408
1443
|
leaseMs;
|
|
1409
1444
|
constructor(opts = {}) {
|
|
1410
1445
|
this.leaseMs = opts.leaseMs ?? DEFAULT_STORE_LEASE_MS;
|
|
@@ -1447,6 +1482,7 @@ var InMemoryStore = class {
|
|
|
1447
1482
|
for (const key of this.leases.keys()) {
|
|
1448
1483
|
if (key.startsWith(leasePrefix)) this.leases.delete(key);
|
|
1449
1484
|
}
|
|
1485
|
+
this.signalTimers.delete(`${runId}::${fact.stepId}`);
|
|
1450
1486
|
}
|
|
1451
1487
|
}
|
|
1452
1488
|
async tryStartRun(runId, fact, concurrency) {
|
|
@@ -1604,9 +1640,44 @@ var InMemoryStore = class {
|
|
|
1604
1640
|
case "deliver":
|
|
1605
1641
|
await this.appendFact(runId, decision.received);
|
|
1606
1642
|
await this.appendFact(runId, decision.completed);
|
|
1643
|
+
this.signalTimers.delete(`${runId}::${stepId}`);
|
|
1607
1644
|
return decision.result;
|
|
1608
1645
|
}
|
|
1609
1646
|
}
|
|
1647
|
+
async upsertTimer(runId, stepId, fireAt) {
|
|
1648
|
+
const key = `${runId}::${stepId}`;
|
|
1649
|
+
if (!this.signalTimers.has(key)) this.signalTimers.set(key, fireAt);
|
|
1650
|
+
}
|
|
1651
|
+
async sweepSignalTimeouts(args) {
|
|
1652
|
+
const { now, limit = 100 } = args;
|
|
1653
|
+
const timedOut = [];
|
|
1654
|
+
const due = [];
|
|
1655
|
+
for (const [key, fireAt] of this.signalTimers) {
|
|
1656
|
+
if (due.length >= limit) break;
|
|
1657
|
+
if (fireAt > now) continue;
|
|
1658
|
+
const sep = key.indexOf("::");
|
|
1659
|
+
due.push({
|
|
1660
|
+
key,
|
|
1661
|
+
runId: key.slice(0, sep),
|
|
1662
|
+
stepId: key.slice(sep + 2)
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
for (const { key, runId, stepId } of due) {
|
|
1666
|
+
const fireAt = this.signalTimers.get(key);
|
|
1667
|
+
if (fireAt === void 0) continue;
|
|
1668
|
+
const runState = foldRun(runId, this.facts.get(runId) ?? []);
|
|
1669
|
+
const decision = decideTimeout({ runState, stepId, fireAt, at: now });
|
|
1670
|
+
this.signalTimers.delete(key);
|
|
1671
|
+
if (decision.kind === "noop") continue;
|
|
1672
|
+
await this.appendFact(runId, decision.fact);
|
|
1673
|
+
const leasePrefix = `${runId}::${stepId}::`;
|
|
1674
|
+
for (const k of this.leases.keys()) {
|
|
1675
|
+
if (k.startsWith(leasePrefix)) this.leases.delete(k);
|
|
1676
|
+
}
|
|
1677
|
+
timedOut.push({ runId, stepId, attempt: decision.attempt, fireAt });
|
|
1678
|
+
}
|
|
1679
|
+
return timedOut;
|
|
1680
|
+
}
|
|
1610
1681
|
async recordOnce(runId, stepId, scope, value) {
|
|
1611
1682
|
this.onces.set(`${runId}::${stepId}::${scope}`, value);
|
|
1612
1683
|
}
|
|
@@ -2564,10 +2635,18 @@ function makeMessage(deps, hooks, progression) {
|
|
|
2564
2635
|
const { store, clock } = deps;
|
|
2565
2636
|
const { runId, stepId, attempt } = message;
|
|
2566
2637
|
const handler = handlerDef(def);
|
|
2638
|
+
const startedAt = clock.now();
|
|
2567
2639
|
await store.appendFact(
|
|
2568
2640
|
runId,
|
|
2569
|
-
Facts.stepStarted(runId, stepId, attempt, def.kind,
|
|
2641
|
+
Facts.stepStarted(runId, stepId, attempt, def.kind, startedAt)
|
|
2570
2642
|
);
|
|
2643
|
+
if (def.kind === "signal" && def.timeoutMs != null) {
|
|
2644
|
+
await store.upsertTimer(
|
|
2645
|
+
runId,
|
|
2646
|
+
stepId,
|
|
2647
|
+
new Date(startedAt.getTime() + def.timeoutMs)
|
|
2648
|
+
);
|
|
2649
|
+
}
|
|
2571
2650
|
const startCarriesInput = def.kind === "task" || def.kind === "activity" || def.kind === "streaming" || def.kind === "subflow";
|
|
2572
2651
|
const input = startCarriesInput ? state.input : null;
|
|
2573
2652
|
await fireStepLifecycle(
|
|
@@ -3140,10 +3219,36 @@ function makeDispatcher(deps) {
|
|
|
3140
3219
|
const hooks = makeHooks(deps);
|
|
3141
3220
|
const progression = makeProgression(deps, hooks);
|
|
3142
3221
|
const message = makeMessage(deps, hooks, progression);
|
|
3222
|
+
async function sweepTimers(now) {
|
|
3223
|
+
const timedOut = await deps.store.sweepSignalTimeouts({ now });
|
|
3224
|
+
for (const { runId, stepId, attempt, fireAt } of timedOut) {
|
|
3225
|
+
if (deps.hooks?.onStepError) {
|
|
3226
|
+
const flow2 = await deps.flowFor(runId);
|
|
3227
|
+
await hooks.fireHook(
|
|
3228
|
+
deps.hooks.onStepError,
|
|
3229
|
+
{
|
|
3230
|
+
runId,
|
|
3231
|
+
flowId: flow2.id,
|
|
3232
|
+
stepId,
|
|
3233
|
+
attempt,
|
|
3234
|
+
kind: "signal",
|
|
3235
|
+
error: serializeError(
|
|
3236
|
+
new NagiSignalTimeoutError({ runId, stepId, fireAt })
|
|
3237
|
+
),
|
|
3238
|
+
at: now
|
|
3239
|
+
},
|
|
3240
|
+
"onStepError"
|
|
3241
|
+
);
|
|
3242
|
+
}
|
|
3243
|
+
await progression.advance(runId);
|
|
3244
|
+
}
|
|
3245
|
+
return timedOut.length;
|
|
3246
|
+
}
|
|
3143
3247
|
return {
|
|
3144
3248
|
dispatchMessage: message.dispatchMessage,
|
|
3145
3249
|
advance: progression.advance,
|
|
3146
|
-
propagateToParent: progression.propagateToParent
|
|
3250
|
+
propagateToParent: progression.propagateToParent,
|
|
3251
|
+
sweepTimers
|
|
3147
3252
|
};
|
|
3148
3253
|
}
|
|
3149
3254
|
|
|
@@ -3444,6 +3549,7 @@ async function drainInline(dispatcher, queue) {
|
|
|
3444
3549
|
// src/worker.ts
|
|
3445
3550
|
var DEFAULT_CONCURRENCY = 4;
|
|
3446
3551
|
var DEFAULT_POLL_INTERVAL_MS = 1e3;
|
|
3552
|
+
var DEFAULT_TIMER_SWEEP_INTERVAL_MS = 3e4;
|
|
3447
3553
|
function makeWorker(deps, config) {
|
|
3448
3554
|
return new WorkerImpl(deps, config);
|
|
3449
3555
|
}
|
|
@@ -3454,6 +3560,8 @@ var WorkerImpl = class {
|
|
|
3454
3560
|
this.pollIntervalMs = config?.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
3455
3561
|
this.signal = config?.signal;
|
|
3456
3562
|
this.dispatcher = makeDispatcher(deps);
|
|
3563
|
+
this.timerSweepIntervalMs = config?.timerSweepIntervalMs ?? DEFAULT_TIMER_SWEEP_INTERVAL_MS;
|
|
3564
|
+
this.lastTimerSweepAt = this.deps.clock.now().getTime();
|
|
3457
3565
|
}
|
|
3458
3566
|
deps;
|
|
3459
3567
|
inFlight = 0;
|
|
@@ -3461,8 +3569,11 @@ var WorkerImpl = class {
|
|
|
3461
3569
|
pollIntervalMs;
|
|
3462
3570
|
signal;
|
|
3463
3571
|
dispatcher;
|
|
3572
|
+
timerSweepIntervalMs;
|
|
3573
|
+
lastTimerSweepAt;
|
|
3464
3574
|
async run() {
|
|
3465
3575
|
while (!this.aborted()) {
|
|
3576
|
+
await this.maybeSweepTimers();
|
|
3466
3577
|
const slots = this.concurrency - this.inFlight;
|
|
3467
3578
|
if (slots <= 0) {
|
|
3468
3579
|
await this.sleep(50);
|
|
@@ -3547,6 +3658,26 @@ var WorkerImpl = class {
|
|
|
3547
3658
|
await this.deps.clock.sleep(50);
|
|
3548
3659
|
}
|
|
3549
3660
|
}
|
|
3661
|
+
// Sweep elapsed signal timeouts on cadence. Runs inline in the dispatch loop
|
|
3662
|
+
// (not fired concurrently) so two sweeps never overlap; at 30s with a handful
|
|
3663
|
+
// of timers the cost is negligible. Errors are logged, never thrown — a failed
|
|
3664
|
+
// sweep must not kill the worker; the next tick retries.
|
|
3665
|
+
async maybeSweepTimers() {
|
|
3666
|
+
if (this.timerSweepIntervalMs <= 0) return;
|
|
3667
|
+
const now = this.deps.clock.now();
|
|
3668
|
+
if (now.getTime() - this.lastTimerSweepAt < this.timerSweepIntervalMs)
|
|
3669
|
+
return;
|
|
3670
|
+
this.lastTimerSweepAt = now.getTime();
|
|
3671
|
+
try {
|
|
3672
|
+
await this.dispatcher.sweepTimers(now);
|
|
3673
|
+
} catch (err) {
|
|
3674
|
+
this.deps.emitLog({
|
|
3675
|
+
level: "warn",
|
|
3676
|
+
msg: "worker: signal-timeout sweep failed",
|
|
3677
|
+
attrs: { error: String(err) }
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3550
3681
|
aborted() {
|
|
3551
3682
|
return this.signal?.aborted === true;
|
|
3552
3683
|
}
|
|
@@ -4095,6 +4226,6 @@ function bindQueueToTx(queue, tx) {
|
|
|
4095
4226
|
return queue;
|
|
4096
4227
|
}
|
|
4097
4228
|
|
|
4098
|
-
export { DEFAULT_REAPER_INTERVAL_MS, InMemoryClock, InMemoryQueue, InMemoryStore, InMemoryTrigger, NagiAbortError, NagiCanceledError, NagiConcurrencyConflictError, NagiFlowSnapshotGoneError, NagiRuntimeError, NagiSnapshotDriftError, NagiValidationError, RunId, attemptOf, canonicalize, decideExpiredLeaseAction, decideSignal, diffSnapshots, errorOf, fingerprintFlows, flow, isStepTerminal, isTerminalRun, nagi, optional, outputOf, foldRun as projectRunState, resolvedOf, runStatusOf, sha256Canonical, stepStateOf, stepStatusOf, unwrap };
|
|
4229
|
+
export { DEFAULT_REAPER_INTERVAL_MS, InMemoryClock, InMemoryQueue, InMemoryStore, InMemoryTrigger, NagiAbortError, NagiCanceledError, NagiConcurrencyConflictError, NagiFlowSnapshotGoneError, NagiRuntimeError, NagiSignalTimeoutError, NagiSnapshotDriftError, NagiValidationError, RunId, attemptOf, canonicalize, decideExpiredLeaseAction, decideSignal, decideTimeout, diffSnapshots, errorOf, fingerprintFlows, flow, isStepTerminal, isTerminalRun, nagi, optional, outputOf, foldRun as projectRunState, resolvedOf, runStatusOf, sha256Canonical, stepStateOf, stepStatusOf, unwrap };
|
|
4099
4230
|
//# sourceMappingURL=index.js.map
|
|
4100
4231
|
//# sourceMappingURL=index.js.map
|