@effect-agent/platform-cloudflare 0.1.0-beta.112 → 0.1.0-beta.113
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/Alarm.d.mts +35 -11
- package/dist/Alarm.mjs +110 -24
- package/dist/Alarm.mjs.map +1 -1
- package/dist/CloudflareThreadClient.d.mts +32 -32
- package/dist/{ThreadObject-0k-SVpY_.mjs → ThreadObject-BPt5uByD.mjs} +17 -8
- package/dist/ThreadObject-BPt5uByD.mjs.map +1 -0
- package/dist/{ThreadObject-DVxgrU7c.d.mts → ThreadObject-DAuaRyGl.d.mts} +34 -34
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/ThreadObject.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +234 -36
- package/src/internal/message-delivery.ts +33 -23
- package/dist/ThreadObject-0k-SVpY_.mjs.map +0 -1
package/dist/Alarm.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ import { ThreadProjectionError, ThreadProjectionMaintenance } from "effect-agent
|
|
|
10
10
|
import { WakeScheduler } from "effect-agent/wake-scheduler";
|
|
11
11
|
import { SqlClient } from "effect/unstable/sql/SqlClient";
|
|
12
12
|
declare namespace Alarm_d_exports {
|
|
13
|
-
export { DurableAlarmError, DurableAlarmService, MaintenancePassFailure, MaintenancePassReport, ThreadHostMaintenance, ThreadMaintenance, ThreadMaintenanceFailpoint, ThreadMaintenanceFailpointHandler, ThreadMaintenanceFailpointLocation, ThreadMessageDelivery, ThreadMutationGate, ThreadPublication, ThreadPublicationService, ThreadRecoveryFault, publishCommitted };
|
|
13
|
+
export { DurableAlarmError, DurableAlarmService, MaintenancePassFailure, MaintenancePassReport, ThreadHostMaintenance, ThreadMaintenance, ThreadMaintenanceActivity, ThreadMaintenanceFailpoint, ThreadMaintenanceFailpointHandler, ThreadMaintenanceFailpointLocation, ThreadMessageDelivery, ThreadMutationGate, ThreadPublication, ThreadPublicationService, ThreadRecoveryFault, publishCommitted };
|
|
14
14
|
}
|
|
15
15
|
declare const DurableAlarmError_base: Schema.Class<DurableAlarmError, Schema.TaggedStruct<"DurableAlarmError", {
|
|
16
16
|
readonly operation: Schema.String;
|
|
@@ -114,25 +114,49 @@ declare const ThreadPublication_base: Context.ServiceClass<ThreadPublication, "@
|
|
|
114
114
|
export declare class ThreadPublication extends ThreadPublication_base {
|
|
115
115
|
static readonly layer: Layer.Layer<ThreadPublication, never, never>;
|
|
116
116
|
}
|
|
117
|
+
declare const ThreadMaintenanceActivity_base: Context.ServiceClass<ThreadMaintenanceActivity, "@effect-agent/platform-cloudflare/ThreadMaintenanceActivity", {
|
|
118
|
+
/**
|
|
119
|
+
* Account for one finite selection/dispatch, through joined completion or interruption.
|
|
120
|
+
* Register before reading/claiming work. After dispatch closes the body is not started.
|
|
121
|
+
* Host waves retain their declared allowance from this call; message Claims keep the driver's
|
|
122
|
+
* own deadline. Waiting for notifications belongs outside this bracket.
|
|
123
|
+
*/
|
|
124
|
+
readonly run: <R>(wave: Effect.Effect<void, DurableAlarmError, R>) => Effect.Effect<void, DurableAlarmError, R>;
|
|
125
|
+
/** Acknowledge all initial subscriptions/scans. Composite hosts use `all` below. */
|
|
126
|
+
readonly ready: Effect.Effect<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Acquire an independent scoped subscription before the initial scan and `ready`.
|
|
129
|
+
* The returned wait observes coalesced native scan hints, including those published before
|
|
130
|
+
* its first execution. Each hint requests a current local due-work check.
|
|
131
|
+
*/
|
|
132
|
+
readonly subscribeChanges: Effect.Effect<Effect.Effect<void>, never, Scope.Scope>;
|
|
133
|
+
}>;
|
|
134
|
+
/** Event-local accounting shared by the existing maintenance pumps and native scheduler. */
|
|
135
|
+
export declare class ThreadMaintenanceActivity extends ThreadMaintenanceActivity_base {
|
|
136
|
+
/** Join child pumps; acknowledge the parent only after every child is ready or has exited. */
|
|
137
|
+
static readonly all: <A, E, R>(lanes: readonly Effect.Effect<A, E, R>[]) => Effect.Effect<readonly A[], E, R | ThreadMaintenanceActivity>;
|
|
138
|
+
}
|
|
117
139
|
/**
|
|
118
140
|
* Host-assembled native message recovery. The driver bounds each actual Claim and persists its
|
|
119
141
|
* timeout/retry before this pump returns. Do not add a second timer starting at batch selection:
|
|
120
142
|
* local Claim setup may take time, and expiration still owes the driver's local retry commit.
|
|
121
143
|
*/
|
|
122
144
|
export declare const ThreadMessageDelivery: Context.Reference<{
|
|
123
|
-
readonly drainUntil: (dispatchClosed: Effect.Effect<void>, dispatchUntil: DateTime.Utc) => Effect.Effect<void, DurableAlarmError, Scope.Scope>;
|
|
145
|
+
readonly drainUntil: (dispatchClosed: Effect.Effect<void>, dispatchUntil: DateTime.Utc) => Effect.Effect<void, DurableAlarmError, Scope.Scope | ThreadMaintenanceActivity>;
|
|
124
146
|
readonly pendingDeadline: Effect.Effect<Option.Option<number>, DurableAlarmError>;
|
|
125
147
|
}>;
|
|
126
148
|
/**
|
|
127
149
|
* Application obligations sharing this Object's alarm. Admit one initial external wave even on
|
|
128
|
-
* a caught-up pass, then respond to wakes
|
|
129
|
-
*
|
|
130
|
-
*
|
|
150
|
+
* a caught-up pass, then respond to wakes and ThreadMaintenanceActivity.subscribeChanges until
|
|
151
|
+
* dispatchClosed. Yield the event's ThreadMaintenanceActivity to bracket each finite lane with
|
|
152
|
+
* run and acknowledge initial setup with ready.
|
|
153
|
+
* Passive subscriptions do not count as active work. Closure stops both new waves and native
|
|
154
|
+
* Attempts; local admission/control subscriptions belong to the event Scope until teardown.
|
|
131
155
|
* No deadline sleeps or automatic retry loops. Return after already-admitted waves finish.
|
|
132
156
|
*
|
|
133
157
|
* Declare a finite whole-wave allowance (1..300000ms): maximum for parallel lanes, sum for
|
|
134
158
|
* sequential operations. Admit a wave only if its allowance fits before dispatchUntil. Later
|
|
135
|
-
* arrivals cannot renew
|
|
159
|
+
* arrivals cannot renew an admitted wave's allowance. Maintenance bounds each registered wave,
|
|
136
160
|
* interrupts and joins event Scope, then reads local deadlines under the mutation gate.
|
|
137
161
|
*
|
|
138
162
|
* Setup and pendingDeadline are bounded local operations. Persist claims/envelopes before
|
|
@@ -143,7 +167,7 @@ export declare const ThreadMessageDelivery: Context.Reference<{
|
|
|
143
167
|
*/
|
|
144
168
|
export declare const ThreadHostMaintenance: Context.Reference<{
|
|
145
169
|
readonly dispatchTimeoutMillis: number;
|
|
146
|
-
readonly drainUntil: (dispatchClosed: Effect.Effect<void>, dispatchUntil: DateTime.Utc) => Effect.Effect<void, DurableAlarmError, Scope.Scope>;
|
|
170
|
+
readonly drainUntil: (dispatchClosed: Effect.Effect<void>, dispatchUntil: DateTime.Utc) => Effect.Effect<void, DurableAlarmError, Scope.Scope | ThreadMaintenanceActivity>;
|
|
147
171
|
readonly pendingDeadline: Effect.Effect<Option.Option<number>, DurableAlarmError>;
|
|
148
172
|
}>;
|
|
149
173
|
/** @internal A committed source operation must not become a failed operation because delivery failed. */
|
|
@@ -217,10 +241,10 @@ declare const ThreadMaintenance_base: Context.ServiceClass<ThreadMaintenance, "@
|
|
|
217
241
|
* recovery, ledger scans or canonical-history reads.
|
|
218
242
|
* 2. Reconcile before each head Attempt, then checkpoint only the observed generation. A racing
|
|
219
243
|
* producer keeps its newer generation dirty. Native retries retain their durable backoff.
|
|
220
|
-
* 3. Keep delivery admission open while
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* 4. Native message delivery retains its driver-owned Claim deadline. Host/backfill
|
|
244
|
+
* 3. Keep native and delivery admission open together while finite waves remain active, so
|
|
245
|
+
* fresh replies and abort controls can progress during unrelated cleanup. Close atomically
|
|
246
|
+
* at quiescence, or at the original ten-minute yield deadline, before retiring listeners.
|
|
247
|
+
* 4. Native message delivery retains its driver-owned Claim deadline. Host/backfill waves are
|
|
224
248
|
* bounded independently; incoming native work never restarts or cancels their attempts.
|
|
225
249
|
* Auxiliary failures are reported after the current native opportunity.
|
|
226
250
|
* 5. Close every event resource before the final gated deadline snapshot and alarm decision.
|
package/dist/Alarm.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { DurableObjectContext } from "./CloudflareBindings.mjs";
|
|
3
3
|
import { AuxiliaryDispatchMillis, CloudflareDurableRuntimeConfig } from "./CloudflareConfig.mjs";
|
|
4
4
|
import { r as safeCauseMessage } from "./boundary-BguazVkh.mjs";
|
|
5
|
-
import { Cause, Clock, Context, DateTime, Deferred, Effect, Exit, Fiber, Layer, Option, Random, Ref, Result, Schema, Scope, Semaphore, Stream, Struct } from "effect";
|
|
5
|
+
import { Cause, Clock, Context, DateTime, Deferred, Effect, Exit, Fiber, Layer, Option, PubSub, Random, Ref, Result, Schema, Scope, Semaphore, Stream, Struct } from "effect";
|
|
6
6
|
import "effect-agent/agent-registration";
|
|
7
7
|
import { DurableAgentRuntime, DurableRuntimeConfig, RecoveryBlocked, RecoveryFailure, RecoverySweepResult, isolateRecovery } from "effect-agent/durable-agent-runtime";
|
|
8
8
|
import { SubmissionId, ThreadId } from "effect-agent/identifiers";
|
|
@@ -18,6 +18,7 @@ var Alarm_exports = /* @__PURE__ */ __exportAll({
|
|
|
18
18
|
MaintenancePassReport: () => MaintenancePassReport,
|
|
19
19
|
ThreadHostMaintenance: () => ThreadHostMaintenance,
|
|
20
20
|
ThreadMaintenance: () => ThreadMaintenance,
|
|
21
|
+
ThreadMaintenanceActivity: () => ThreadMaintenanceActivity,
|
|
21
22
|
ThreadMaintenanceFailpoint: () => ThreadMaintenanceFailpoint,
|
|
22
23
|
ThreadMessageDelivery: () => ThreadMessageDelivery,
|
|
23
24
|
ThreadMutationGate: () => ThreadMutationGate,
|
|
@@ -111,6 +112,27 @@ var ThreadPublication = class extends Context.Service()("@effect-agent/platform-
|
|
|
111
112
|
pendingDeadline: Effect.succeed(Option.none())
|
|
112
113
|
});
|
|
113
114
|
};
|
|
115
|
+
/** Event-local accounting shared by the existing maintenance pumps and native scheduler. */
|
|
116
|
+
var ThreadMaintenanceActivity = class ThreadMaintenanceActivity extends Context.Service()("@effect-agent/platform-cloudflare/ThreadMaintenanceActivity") {
|
|
117
|
+
/** Join child pumps; acknowledge the parent only after every child is ready or has exited. */
|
|
118
|
+
static all = Effect.fnUntraced(function* (lanes) {
|
|
119
|
+
const activity = yield* ThreadMaintenanceActivity;
|
|
120
|
+
let remaining = lanes.length;
|
|
121
|
+
if (remaining === 0) return yield* activity.ready.pipe(Effect.as([]));
|
|
122
|
+
return yield* Effect.forEach(lanes, (lane) => {
|
|
123
|
+
let ready = false;
|
|
124
|
+
const child = {
|
|
125
|
+
...activity,
|
|
126
|
+
ready: Effect.suspend(() => {
|
|
127
|
+
if (ready) return Effect.void;
|
|
128
|
+
ready = true;
|
|
129
|
+
return --remaining === 0 ? activity.ready : Effect.void;
|
|
130
|
+
}).pipe(Effect.uninterruptible)
|
|
131
|
+
};
|
|
132
|
+
return lane.pipe(Effect.provideService(ThreadMaintenanceActivity, child), Effect.onExit(() => child.ready));
|
|
133
|
+
}, { concurrency: "unbounded" });
|
|
134
|
+
});
|
|
135
|
+
};
|
|
114
136
|
/**
|
|
115
137
|
* Host-assembled native message recovery. The driver bounds each actual Claim and persists its
|
|
116
138
|
* timeout/retry before this pump returns. Do not add a second timer starting at batch selection:
|
|
@@ -122,14 +144,16 @@ const ThreadMessageDelivery = Context.Reference("@effect-agent/platform-cloudfla
|
|
|
122
144
|
}) });
|
|
123
145
|
/**
|
|
124
146
|
* Application obligations sharing this Object's alarm. Admit one initial external wave even on
|
|
125
|
-
* a caught-up pass, then respond to wakes
|
|
126
|
-
*
|
|
127
|
-
*
|
|
147
|
+
* a caught-up pass, then respond to wakes and ThreadMaintenanceActivity.subscribeChanges until
|
|
148
|
+
* dispatchClosed. Yield the event's ThreadMaintenanceActivity to bracket each finite lane with
|
|
149
|
+
* run and acknowledge initial setup with ready.
|
|
150
|
+
* Passive subscriptions do not count as active work. Closure stops both new waves and native
|
|
151
|
+
* Attempts; local admission/control subscriptions belong to the event Scope until teardown.
|
|
128
152
|
* No deadline sleeps or automatic retry loops. Return after already-admitted waves finish.
|
|
129
153
|
*
|
|
130
154
|
* Declare a finite whole-wave allowance (1..300000ms): maximum for parallel lanes, sum for
|
|
131
155
|
* sequential operations. Admit a wave only if its allowance fits before dispatchUntil. Later
|
|
132
|
-
* arrivals cannot renew
|
|
156
|
+
* arrivals cannot renew an admitted wave's allowance. Maintenance bounds each registered wave,
|
|
133
157
|
* interrupts and joins event Scope, then reads local deadlines under the mutation gate.
|
|
134
158
|
*
|
|
135
159
|
* Setup and pendingDeadline are bounded local operations. Persist claims/envelopes before
|
|
@@ -286,10 +310,10 @@ var ThreadMutationGate = class ThreadMutationGate extends Context.Service()("@ef
|
|
|
286
310
|
* recovery, ledger scans or canonical-history reads.
|
|
287
311
|
* 2. Reconcile before each head Attempt, then checkpoint only the observed generation. A racing
|
|
288
312
|
* producer keeps its newer generation dirty. Native retries retain their durable backoff.
|
|
289
|
-
* 3. Keep delivery admission open while
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* 4. Native message delivery retains its driver-owned Claim deadline. Host/backfill
|
|
313
|
+
* 3. Keep native and delivery admission open together while finite waves remain active, so
|
|
314
|
+
* fresh replies and abort controls can progress during unrelated cleanup. Close atomically
|
|
315
|
+
* at quiescence, or at the original ten-minute yield deadline, before retiring listeners.
|
|
316
|
+
* 4. Native message delivery retains its driver-owned Claim deadline. Host/backfill waves are
|
|
293
317
|
* bounded independently; incoming native work never restarts or cancels their attempts.
|
|
294
318
|
* Auxiliary failures are reported after the current native opportunity.
|
|
295
319
|
* 5. Close every event resource before the final gated deadline snapshot and alarm decision.
|
|
@@ -637,6 +661,47 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
637
661
|
const notified = (yield* Stream.toPull(wakes.wakes)).pipe(Effect.asVoid, Effect.catch(() => Effect.never));
|
|
638
662
|
const started = yield* beginNative(observed);
|
|
639
663
|
const auxiliaryScope = yield* Effect.acquireRelease(Scope.make("parallel"), (scope, exit) => Scope.close(scope, exit));
|
|
664
|
+
const dispatchClosed = yield* Deferred.make();
|
|
665
|
+
const stopDispatch = Deferred.await(dispatchClosed);
|
|
666
|
+
const checks = yield* PubSub.sliding(1);
|
|
667
|
+
yield* Effect.addFinalizer(() => PubSub.shutdown(checks));
|
|
668
|
+
let dispatchOpen = true;
|
|
669
|
+
let activityChanged = yield* Deferred.make();
|
|
670
|
+
const signalActivity = Effect.suspend(() => Deferred.succeed(activityChanged, void 0));
|
|
671
|
+
const closeDispatch = Effect.sync(() => {
|
|
672
|
+
dispatchOpen = false;
|
|
673
|
+
}).pipe(Effect.andThen(Deferred.succeed(dispatchClosed, void 0)));
|
|
674
|
+
const makeActivity = Effect.fnUntraced(function* (allowance) {
|
|
675
|
+
const initialized = yield* Deferred.make();
|
|
676
|
+
let active = 0;
|
|
677
|
+
let failed = false;
|
|
678
|
+
return {
|
|
679
|
+
activity: {
|
|
680
|
+
ready: Deferred.succeed(initialized, void 0).pipe(Effect.andThen(signalActivity), Effect.asVoid, Effect.uninterruptible),
|
|
681
|
+
subscribeChanges: PubSub.subscribe(checks).pipe(Effect.map(PubSub.take)),
|
|
682
|
+
run: (wave) => Effect.acquireUseRelease(Effect.sync(() => {
|
|
683
|
+
if (!dispatchOpen) return false;
|
|
684
|
+
active++;
|
|
685
|
+
return true;
|
|
686
|
+
}), (admitted) => !admitted ? Effect.void : (allowance === void 0 ? wave : wave.pipe(Effect.timeoutOrElse({
|
|
687
|
+
duration: allowance,
|
|
688
|
+
orElse: () => DurableAlarmError.make({
|
|
689
|
+
operation: "host dispatch allowance",
|
|
690
|
+
message: "The admitted host wave exceeded its allowance; durable work remains pending"
|
|
691
|
+
})
|
|
692
|
+
}))).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
693
|
+
if (Exit.isFailure(exit)) failed = true;
|
|
694
|
+
}))), (admitted) => Effect.sync(() => {
|
|
695
|
+
if (admitted) active--;
|
|
696
|
+
}).pipe(Effect.andThen(signalActivity)))
|
|
697
|
+
},
|
|
698
|
+
initialized: Deferred.await(initialized),
|
|
699
|
+
quiet: () => active === 0 && Deferred.isDoneUnsafe(initialized),
|
|
700
|
+
failed: () => failed
|
|
701
|
+
};
|
|
702
|
+
});
|
|
703
|
+
const messageActivity = yield* makeActivity();
|
|
704
|
+
const hostActivity = yield* makeActivity(host.dispatchTimeoutMillis);
|
|
640
705
|
const recovery = {
|
|
641
706
|
queue: yield* Deferred.make(),
|
|
642
707
|
pending: /* @__PURE__ */ new Set(),
|
|
@@ -664,18 +729,23 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
664
729
|
yield* wakes.notify(threadId);
|
|
665
730
|
}
|
|
666
731
|
}), auxiliaryScope);
|
|
667
|
-
const
|
|
668
|
-
const stopDispatch = Deferred.await(dispatchClosed);
|
|
669
|
-
const deliveryFiber = yield* Effect.forkIn(Scope.provide(auxiliaryScope)(messages.drainUntil(stopDispatch, dispatchUntil)), auxiliaryScope);
|
|
732
|
+
const deliveryFiber = yield* Effect.forkIn(Scope.provide(auxiliaryScope)(messages.drainUntil(stopDispatch, dispatchUntil).pipe(Effect.provideService(ThreadMaintenanceActivity, messageActivity.activity), Effect.onExit(() => messageActivity.activity.ready))), auxiliaryScope);
|
|
670
733
|
const hostFiber = yield* Effect.forkIn(Scope.provide(auxiliaryScope)(Effect.gen(function* () {
|
|
671
734
|
yield* Schema.decodeEffect(AuxiliaryDispatchMillis)(host.dispatchTimeoutMillis).pipe(Effect.mapError((cause) => DurableAlarmError.make({
|
|
672
735
|
operation: "host dispatch allowance",
|
|
673
736
|
message: "Declare an integer whole-wave allowance between 1 and 300000 milliseconds",
|
|
674
737
|
cause
|
|
675
738
|
})));
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
739
|
+
const initialization = hostActivity.initialized.pipe(Effect.timeoutOrElse({
|
|
740
|
+
duration: host.dispatchTimeoutMillis,
|
|
741
|
+
orElse: () => DurableAlarmError.make({
|
|
742
|
+
operation: "host initialization",
|
|
743
|
+
message: "The host did not account for initial maintenance before its allowance; durable work remains pending"
|
|
744
|
+
})
|
|
745
|
+
}), Effect.andThen(Effect.never));
|
|
746
|
+
yield* Effect.raceFirst(host.drainUntil(stopDispatch, dispatchUntil).pipe(Effect.provideService(ThreadMaintenanceActivity, hostActivity.activity)), initialization);
|
|
747
|
+
}).pipe(Effect.onExit(() => hostActivity.activity.ready))), auxiliaryScope);
|
|
748
|
+
const backfill = yield* Effect.forkIn(drainDue.pipe(Effect.provideService(ThreadProjectionMaintenance, projection), Effect.timeoutOption(config.projectionDispatchTimeoutMillis), Effect.onExit(() => signalActivity)), auxiliaryScope);
|
|
679
749
|
let result = yield* advance(started, yieldAfter, observed, recovery);
|
|
680
750
|
recovery.started = true;
|
|
681
751
|
yield* Deferred.succeed(recovery.queue, []);
|
|
@@ -694,9 +764,9 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
694
764
|
backfill,
|
|
695
765
|
recoveryFiber
|
|
696
766
|
]));
|
|
697
|
-
const auxiliaryPending = () => deliveryFiber.pollUnsafe() === void 0 || hostFiber.pollUnsafe() === void 0 || backfill.pollUnsafe() === void 0 || recoveryFiber.pollUnsafe() === void 0;
|
|
698
767
|
while (true) {
|
|
699
768
|
const recoveryFinished = recoveryFiber.pollUnsafe() !== void 0;
|
|
769
|
+
const retiredExit = retired.pollUnsafe();
|
|
700
770
|
if (recoveryFinished) {
|
|
701
771
|
if (recovery.needsCheckpoint) {
|
|
702
772
|
yield* Fiber.join(recoveryFiber);
|
|
@@ -704,27 +774,43 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
704
774
|
if (result.phase === "actionable") phase = "actionable";
|
|
705
775
|
settled += result.settled;
|
|
706
776
|
recovery.needsCheckpoint = false;
|
|
777
|
+
yield* PubSub.publish(checks, void 0);
|
|
707
778
|
}
|
|
708
|
-
yield* Deferred.succeed(dispatchClosed, void 0);
|
|
709
779
|
}
|
|
710
|
-
if (
|
|
780
|
+
if (retiredExit !== void 0 && Exit.isFailure(retiredExit)) break;
|
|
781
|
+
if (recoveryFinished && backfill.pollUnsafe() !== void 0 && messageActivity.quiet() && hostActivity.quiet()) {
|
|
782
|
+
const now = yield* Clock.currentTimeMillis;
|
|
783
|
+
const messageDeadline = yield* messages.pendingDeadline;
|
|
784
|
+
const hostDeadline = yield* host.pendingDeadline;
|
|
785
|
+
const messageDue = deliveryFiber.pollUnsafe() === void 0 && !messageActivity.failed() && Option.isSome(messageDeadline) && messageDeadline.value <= now;
|
|
786
|
+
const hostDue = hostFiber.pollUnsafe() === void 0 && !hostActivity.failed() && now + host.dispatchTimeoutMillis <= DateTime.toEpochMillis(dispatchUntil) && Option.isSome(hostDeadline) && hostDeadline.value <= now;
|
|
787
|
+
if (yield* Effect.sync(() => {
|
|
788
|
+
if (messageDue || hostDue || !messageActivity.quiet() || !hostActivity.quiet()) return false;
|
|
789
|
+
dispatchOpen = false;
|
|
790
|
+
return true;
|
|
791
|
+
})) break;
|
|
792
|
+
yield* PubSub.publish(checks, void 0);
|
|
793
|
+
}
|
|
711
794
|
const now = yield* Clock.currentTimeMillis;
|
|
712
795
|
const until = DateTime.toEpochMillis(yieldAfter);
|
|
713
796
|
if (now >= until) break;
|
|
714
797
|
const next = Math.min(result.nextAttemptAt ?? Infinity, now + config.wakeScanInterval, until);
|
|
715
798
|
const recoveryDone = recoveryFinished ? Effect.never : Fiber.await(recoveryFiber);
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
if (
|
|
799
|
+
const retirementDone = retiredExit === void 0 ? Fiber.await(retired) : Effect.never;
|
|
800
|
+
const changed = activityChanged;
|
|
801
|
+
const ready = yield* Effect.raceFirst(Effect.raceFirst(notified, Effect.sleep(Math.max(0, next - now))).pipe(Effect.as("native")), Effect.raceFirst(recoveryDone.pipe(Effect.as("recovery")), Effect.raceFirst(retirementDone.pipe(Effect.as("retired")), Deferred.await(changed).pipe(Effect.as("activity")))));
|
|
802
|
+
if (ready === "recovery" || ready === "retired") continue;
|
|
803
|
+
if (ready === "activity") activityChanged = yield* Deferred.make();
|
|
720
804
|
if ((yield* Clock.currentTimeMillis) >= until) break;
|
|
805
|
+
if (ready === "native") yield* PubSub.publish(checks, void 0);
|
|
721
806
|
const awakened = yield* beginNative(observed);
|
|
722
807
|
result = yield* advance(awakened, yieldAfter, observed, recovery);
|
|
723
808
|
if (result.phase === "actionable") phase = "actionable";
|
|
724
809
|
settled += result.settled;
|
|
725
810
|
observed.nativeOnly = false;
|
|
811
|
+
if (result.settled > 0) yield* PubSub.publish(checks, void 0);
|
|
726
812
|
}
|
|
727
|
-
yield*
|
|
813
|
+
yield* closeDispatch;
|
|
728
814
|
yield* Fiber.join(retired);
|
|
729
815
|
if (recovery.needsCheckpoint) {
|
|
730
816
|
result = yield* advance(started, yieldAfter, observed, recovery, false);
|
|
@@ -786,6 +872,6 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
786
872
|
}));
|
|
787
873
|
};
|
|
788
874
|
//#endregion
|
|
789
|
-
export { DurableAlarmError, DurableAlarmService, MaintenancePassReport, ThreadHostMaintenance, ThreadMaintenance, ThreadMaintenanceFailpoint, ThreadMessageDelivery, ThreadMutationGate, ThreadPublication, ThreadRecoveryFault, publishCommitted, Alarm_exports as t };
|
|
875
|
+
export { DurableAlarmError, DurableAlarmService, MaintenancePassReport, ThreadHostMaintenance, ThreadMaintenance, ThreadMaintenanceActivity, ThreadMaintenanceFailpoint, ThreadMessageDelivery, ThreadMutationGate, ThreadPublication, ThreadRecoveryFault, publishCommitted, Alarm_exports as t };
|
|
790
876
|
|
|
791
877
|
//# sourceMappingURL=Alarm.mjs.map
|