@systemfsoftware/effect-daemon-spec 3.0.4 → 3.0.6
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/CHANGELOG.md +19 -0
- package/dist/index.mjs +89 -71
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @systemfsoftware/effect-daemon-spec
|
|
2
2
|
|
|
3
|
+
## 3.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Peer Effect requirement advances to 4.0.0-rc.112. No API changes.
|
|
8
|
+
|
|
9
|
+
- The arbitraries derived for several schema filters now construct their valid values directly instead of drawing many samples and discarding them. Filtered schemas such as the worker-call guard, the edit-entry guards, and the restart-cap check generate matching values on the first draws, so property suites that use them finish faster. Every value still satisfies the same filter as before.
|
|
10
|
+
|
|
11
|
+
## 3.0.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Re-released to propagate the effect-cell-types and stryker-js workflow-channel migration into their published dependency graphs; no package-local API change
|
|
16
|
+
|
|
17
|
+
- The arbitraries derived for several schema filters now construct their valid values directly instead of drawing many samples and discarding them. Filtered schemas such as the worker-call guard, the edit-entry guards, and the restart-cap check generate matching values on the first draws, so property suites that use them finish faster. Every value still satisfies the same filter as before.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies:
|
|
20
|
+
- @systemfsoftware/effect-cell-types@6.0.0
|
|
21
|
+
|
|
3
22
|
## 3.0.4
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array, Cause, Clock, Context, Duration, Effect, Equal, Exit, Fiber, HashMap, Latch, Layer, Match, Metric, Option, Predicate, Ref, Result, Schedule, Schema, Scope, Stream
|
|
1
|
+
import { Array, Cause, Clock, Context, Duration, Effect, Equal, Exit, Fiber, HashMap, Latch, Layer, Match, Metric, Option, Predicate, Ref, Result, Schedule, Schema, Scope, Stream } from "effect";
|
|
2
2
|
import { Cell, Workflow } from "@systemfsoftware/effect-cell-types";
|
|
3
3
|
import * as Arr from "effect/Array";
|
|
4
4
|
import * as Match$1 from "effect/Match";
|
|
@@ -17,7 +17,6 @@ const DynamicSpecTypeId = Symbol.for("@systemfsoftware/effect-daemon/DynamicSpec
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/DaemonHealth.schema.ts
|
|
19
19
|
var DynamicLimitExceeded = class extends Schema.TaggedError()("DynamicLimitExceeded", { limit: Schema.Int.pipe(Schema.check(Schema.isGreaterThanOrEqualTo(0))) }) {};
|
|
20
|
-
Schema.decodeUnknownExit(DynamicLimitExceeded);
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/DaemonMetrics.ts
|
|
23
22
|
const supervisorRestartsCounter = Metric.counter("app.daemon.supervisor.restart", { description: "Daemon supervisor restart count" });
|
|
@@ -55,10 +54,10 @@ var ChildPolicyConfig = class extends Schema.Class("ChildPolicyConfig")({
|
|
|
55
54
|
])),
|
|
56
55
|
intensity: Schema.optional(IntensityConfig)
|
|
57
56
|
}) {};
|
|
58
|
-
|
|
57
|
+
Schema.Class("SupervisorPolicyConfig")({
|
|
59
58
|
intensity: Schema.optional(IntensityConfig),
|
|
60
59
|
cooldown: Schema.optional(Schema.Duration)
|
|
61
|
-
})
|
|
60
|
+
});
|
|
62
61
|
var LockPolicyConfig = class extends Schema.Class("LockPolicyConfig")({
|
|
63
62
|
mode: Schema.optional(Schema.Literals([
|
|
64
63
|
"none",
|
|
@@ -76,11 +75,6 @@ const MaxChildren = Schema.Int.pipe(Schema.check(Schema.isBetween({
|
|
|
76
75
|
minimum: 1,
|
|
77
76
|
maximum: MAX_CHILDREN_CEILING
|
|
78
77
|
})), Schema.brand("MaxChildren"));
|
|
79
|
-
Schema.Int.pipe(Schema.check(Schema.makeFilter((children) => children < 1 || children > 1e3)));
|
|
80
|
-
Schema.decodeUnknownExit(ChildPolicyConfig);
|
|
81
|
-
Schema.decodeUnknownExit(LockPolicyConfig);
|
|
82
|
-
Schema.decodeUnknownExit(TickPolicyConfig);
|
|
83
|
-
Schema.decodeUnknownExit(SupervisorPolicyConfig);
|
|
84
78
|
//#endregion
|
|
85
79
|
//#region src/DaemonReporterAdapter.ts
|
|
86
80
|
var DaemonReporter = class extends Context.Service()("@systemfsoftware/effect-daemon-spec/DaemonReporterAdapter/DaemonReporter") {};
|
|
@@ -421,53 +415,6 @@ const dynamic$1 = (spec) => Effect.gen(function* () {
|
|
|
421
415
|
return yield* buildDynamic(spec, health);
|
|
422
416
|
});
|
|
423
417
|
//#endregion
|
|
424
|
-
//#region src/internal/IntensityWindow.ts
|
|
425
|
-
/** @internal */
|
|
426
|
-
const isWithinWindow = (now, windowMillis) => (t) => now - t <= windowMillis;
|
|
427
|
-
const keepWithin = (now, windowMillis) => (ts) => ts.filter(isWithinWindow(now, windowMillis));
|
|
428
|
-
/** @internal */
|
|
429
|
-
const pruneTimestamps = (ts, now, windowMillis) => keepWithin(now, windowMillis)(ts);
|
|
430
|
-
/** @internal */
|
|
431
|
-
const recordTimestamp = (ts, now, windowMillis) => [now, ...pruneTimestamps(ts, now, windowMillis)];
|
|
432
|
-
/** @internal */
|
|
433
|
-
const exceedsRestarts = (count, restarts) => count > restarts;
|
|
434
|
-
//#endregion
|
|
435
|
-
//#region src/internal/Intensity.ts
|
|
436
|
-
/** @internal */
|
|
437
|
-
const neverExceeds = {
|
|
438
|
-
record: Effect.void,
|
|
439
|
-
isExceeded: Effect.succeed(false),
|
|
440
|
-
count: Effect.succeed(0)
|
|
441
|
-
};
|
|
442
|
-
/** @internal */
|
|
443
|
-
const make = (restarts, window) => Effect.gen(function* () {
|
|
444
|
-
const windowMillis = Duration.toMillis(window);
|
|
445
|
-
const timestamps = yield* Ref.make([]);
|
|
446
|
-
const prune = (now) => Ref.modify(timestamps, (ts) => {
|
|
447
|
-
const active = pruneTimestamps(ts, now, windowMillis);
|
|
448
|
-
return [active, active];
|
|
449
|
-
});
|
|
450
|
-
return {
|
|
451
|
-
record: Effect.gen(function* () {
|
|
452
|
-
const now = yield* Clock.currentTimeMillis;
|
|
453
|
-
yield* Ref.update(timestamps, (ts) => recordTimestamp(ts, now, windowMillis));
|
|
454
|
-
}),
|
|
455
|
-
isExceeded: Effect.gen(function* () {
|
|
456
|
-
const now = yield* Clock.currentTimeMillis;
|
|
457
|
-
const active = yield* prune(now);
|
|
458
|
-
return exceedsRestarts(active.length, restarts);
|
|
459
|
-
}),
|
|
460
|
-
count: Effect.gen(function* () {
|
|
461
|
-
const now = yield* Clock.currentTimeMillis;
|
|
462
|
-
return (yield* prune(now)).length;
|
|
463
|
-
})
|
|
464
|
-
};
|
|
465
|
-
});
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region src/internal/RaceForExit.ts
|
|
468
|
-
/** @internal */
|
|
469
|
-
const raceForExit = (fibers) => Effect.raceAll(fibers.map((f, idx) => Fiber.await(f).pipe(Effect.map((exit) => [idx, exit]))));
|
|
470
|
-
//#endregion
|
|
471
418
|
//#region src/internal/RestartDecision.schema.ts
|
|
472
419
|
/** @internal */
|
|
473
420
|
const RestartStrategy = Schema.Literals([
|
|
@@ -510,7 +457,25 @@ const DecideInputBase = Schema.Struct({
|
|
|
510
457
|
}))),
|
|
511
458
|
exitSuccess: Schema.Boolean,
|
|
512
459
|
intensityExceeded: Schema.Boolean
|
|
513
|
-
}).pipe(Schema.check(Schema.makeFilter(failedIndexAddressesAChild, {
|
|
460
|
+
}).pipe(Schema.check(Schema.makeFilter(failedIndexAddressesAChild, {
|
|
461
|
+
message: "failedIndex must be < totalChildren",
|
|
462
|
+
arbitrary: { candidate: {
|
|
463
|
+
weight: 20,
|
|
464
|
+
make: (fc) => fc.integer({
|
|
465
|
+
min: 1,
|
|
466
|
+
max: MAX_CHILDREN_CEILING
|
|
467
|
+
}).chain((totalChildren) => fc.record({
|
|
468
|
+
strategy: fc.constantFrom("one_for_one", "one_for_all", "rest_for_one"),
|
|
469
|
+
totalChildren: fc.constant(totalChildren),
|
|
470
|
+
failedIndex: fc.integer({
|
|
471
|
+
min: 0,
|
|
472
|
+
max: totalChildren - 1
|
|
473
|
+
}),
|
|
474
|
+
exitSuccess: fc.boolean(),
|
|
475
|
+
intensityExceeded: fc.boolean()
|
|
476
|
+
}))
|
|
477
|
+
} }
|
|
478
|
+
})));
|
|
514
479
|
/**
|
|
515
480
|
* The restart command. A `Schema.Class` rather than a `Schema.Struct` because `Workflow.make`
|
|
516
481
|
* takes the command's class as its first argument, and a struct carries no `identifier` and
|
|
@@ -520,7 +485,7 @@ const DecideInputBase = Schema.Struct({
|
|
|
520
485
|
/** @internal */
|
|
521
486
|
var DecideInput = class extends Schema.Class("DecideInput")(DecideInputBase) {};
|
|
522
487
|
//#endregion
|
|
523
|
-
//#region src/internal/
|
|
488
|
+
//#region src/internal/choose-restart-strategy.workflow.ts
|
|
524
489
|
/**
|
|
525
490
|
* The child indices a restart covers, by supervision strategy.
|
|
526
491
|
*
|
|
@@ -543,11 +508,58 @@ var RestartDecisionExhausted = class extends S.TaggedError()("Exhausted", {}) {
|
|
|
543
508
|
[RestartDecisionTypeId] = RestartDecisionTypeId;
|
|
544
509
|
};
|
|
545
510
|
/** @internal */
|
|
546
|
-
const
|
|
511
|
+
const chooseRestartStrategy = Workflow.make(DecideInput, (command) => Match$1.value(command).pipe(Match$1.when({ exitSuccess: true }, () => Result$1.succeed(RestartDecisionContinue.make())), Match$1.when({
|
|
547
512
|
exitSuccess: false,
|
|
548
513
|
intensityExceeded: true
|
|
549
514
|
}, () => Result$1.fail(RestartDecisionExhausted.make())), Match$1.orElse(() => Result$1.succeed(RestartDecisionRestart.make({ indices: restartIndicesFor(command.strategy, command.failedIndex, command.totalChildren) })))));
|
|
550
515
|
//#endregion
|
|
516
|
+
//#region src/internal/IntensityWindow.ts
|
|
517
|
+
/** @internal */
|
|
518
|
+
const isWithinWindow = (now, windowMillis) => (t) => now - t <= windowMillis;
|
|
519
|
+
const keepWithin = (now, windowMillis) => (ts) => ts.filter(isWithinWindow(now, windowMillis));
|
|
520
|
+
/** @internal */
|
|
521
|
+
const pruneTimestamps = (ts, now, windowMillis) => keepWithin(now, windowMillis)(ts);
|
|
522
|
+
/** @internal */
|
|
523
|
+
const recordTimestamp = (ts, now, windowMillis) => [now, ...pruneTimestamps(ts, now, windowMillis)];
|
|
524
|
+
/** @internal */
|
|
525
|
+
const exceedsRestarts = (count, restarts) => count > restarts;
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region src/internal/Intensity.ts
|
|
528
|
+
/** @internal */
|
|
529
|
+
const neverExceeds = {
|
|
530
|
+
record: Effect.void,
|
|
531
|
+
isExceeded: Effect.succeed(false),
|
|
532
|
+
count: Effect.succeed(0)
|
|
533
|
+
};
|
|
534
|
+
/** @internal */
|
|
535
|
+
const make = (restarts, window) => Effect.gen(function* () {
|
|
536
|
+
const windowMillis = Duration.toMillis(window);
|
|
537
|
+
const timestamps = yield* Ref.make([]);
|
|
538
|
+
const prune = (now) => Ref.modify(timestamps, (ts) => {
|
|
539
|
+
const active = pruneTimestamps(ts, now, windowMillis);
|
|
540
|
+
return [active, active];
|
|
541
|
+
});
|
|
542
|
+
return {
|
|
543
|
+
record: Effect.gen(function* () {
|
|
544
|
+
const now = yield* Clock.currentTimeMillis;
|
|
545
|
+
yield* Ref.update(timestamps, (ts) => recordTimestamp(ts, now, windowMillis));
|
|
546
|
+
}),
|
|
547
|
+
isExceeded: Effect.gen(function* () {
|
|
548
|
+
const now = yield* Clock.currentTimeMillis;
|
|
549
|
+
const active = yield* prune(now);
|
|
550
|
+
return exceedsRestarts(active.length, restarts);
|
|
551
|
+
}),
|
|
552
|
+
count: Effect.gen(function* () {
|
|
553
|
+
const now = yield* Clock.currentTimeMillis;
|
|
554
|
+
return (yield* prune(now)).length;
|
|
555
|
+
})
|
|
556
|
+
};
|
|
557
|
+
});
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region src/internal/RaceForExit.ts
|
|
560
|
+
/** @internal */
|
|
561
|
+
const raceForExit = (fibers) => Effect.raceAll(fibers.map((f, idx) => Fiber.await(f).pipe(Effect.map((exit) => [idx, exit]))));
|
|
562
|
+
//#endregion
|
|
551
563
|
//#region src/internal/SupervisionEpoch.schema.ts
|
|
552
564
|
const EpochStepTypeId = Symbol.for("@systemfsoftware/effect-daemon/EpochStep");
|
|
553
565
|
/** @internal */
|
|
@@ -655,16 +667,22 @@ const handleRestart = (ctx, cause, onSignal) => Effect.gen(function* () {
|
|
|
655
667
|
* phase signatures hand the command to the read alone. Restarts are rare, so the allocation is
|
|
656
668
|
* paid only when a supervised child has actually died.
|
|
657
669
|
*/
|
|
658
|
-
const restartDescription = (spec) =>
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
670
|
+
const restartDescription = (spec) => Cell.layer({
|
|
671
|
+
read: (intensity) => Effect.andThen(intensity.record, intensity.isExceeded),
|
|
672
|
+
decode: (intensityExceeded) => Result.succeed({
|
|
673
|
+
strategy: spec.strategy,
|
|
674
|
+
totalChildren: spec.totalChildren,
|
|
675
|
+
failedIndex: spec.failedIndex,
|
|
676
|
+
exitSuccess: false,
|
|
677
|
+
intensityExceeded
|
|
678
|
+
}),
|
|
679
|
+
decide: chooseRestartStrategy,
|
|
680
|
+
encode: (outcome) => outcome,
|
|
681
|
+
write: (outcome) => Result.match(outcome, {
|
|
682
|
+
onFailure: () => handleExhausted(spec.ctx, spec.cause),
|
|
683
|
+
onSuccess: (right) => Match.value(right).pipe(Match.tag("Continue", () => Effect.succeed(StopEpoch.make())), Match.tag("Restart", (decision) => handleRestart(spec.ctx, spec.cause, spec.onRestart(decision))), Match.exhaustive)
|
|
684
|
+
})
|
|
685
|
+
});
|
|
668
686
|
const reopenHealthyAfterCooldown = (ctx) => Effect.andThen(ctx.health.healthy.open, Metric.update(Metric.withAttributes(healthStateGauge, {
|
|
669
687
|
daemon: ctx.name,
|
|
670
688
|
latch: "healthy"
|
|
@@ -722,7 +740,7 @@ const superviseChild = (ctx, child, idx) => Effect.gen(function* () {
|
|
|
722
740
|
if (!Exit.isSuccess(exit)) {
|
|
723
741
|
if (child.childPolicy.restart === "temporary") return StopEpoch.make();
|
|
724
742
|
if (yield* isChildIntensityBudgetDone(childIntensityOpt)) return StopEpoch.make();
|
|
725
|
-
return yield* Cell.
|
|
743
|
+
return yield* Cell.run(restartDescription({
|
|
726
744
|
strategy: "one_for_one",
|
|
727
745
|
failedIndex: idx,
|
|
728
746
|
totalChildren: ctx.booted.length,
|
|
@@ -767,7 +785,7 @@ const runGroup = (strategy, ctx) => Effect.gen(function* () {
|
|
|
767
785
|
if (failedBootedOpt.value.childPolicy.restart === "temporary") return StopEpoch.make();
|
|
768
786
|
const cIntForFailed = Option.flatten(Array.get(childIntensityTrackers, failedIdx));
|
|
769
787
|
if (yield* isChildIntensityBudgetDone(cIntForFailed)) return StopEpoch.make();
|
|
770
|
-
return yield* Cell.
|
|
788
|
+
return yield* Cell.run(restartDescription({
|
|
771
789
|
strategy,
|
|
772
790
|
failedIndex: failedIdx,
|
|
773
791
|
totalChildren: ctx.booted.length,
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-daemon-spec",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.6",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/systemfsoftware/systemfsoftware.git",
|
|
9
|
-
"directory": "packages/
|
|
9
|
+
"directory": "packages/effect-daemon-spec"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/
|
|
11
|
+
"homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/effect-daemon-spec#readme",
|
|
12
12
|
"bugs": "https://github.com/systemfsoftware/systemfsoftware/issues",
|
|
13
13
|
"description": "Supervision-tree daemons for Effect-TS — leader election, distributed locks, restart-intensity backoff, dynamic children, and health latches as a pure typed core.",
|
|
14
14
|
"keywords": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@systemfsoftware/effect-cell-types": "^
|
|
40
|
+
"@systemfsoftware/effect-cell-types": "^6.0.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@effect/vitest": "4.0.0-rc.112",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"tsdown": "^0.22.14",
|
|
53
53
|
"typescript": "^7",
|
|
54
54
|
"vitest": "^4",
|
|
55
|
-
"@systemfsoftware/effect-schema-
|
|
56
|
-
"@systemfsoftware/effect-
|
|
55
|
+
"@systemfsoftware/effect-schema-vite": "^2.0.3",
|
|
56
|
+
"@systemfsoftware/effect-schema-law": "^2.0.2",
|
|
57
|
+
"@systemfsoftware/oxlint-plugin-cell-vocabulary": "^2.0.1",
|
|
57
58
|
"@systemfsoftware/oxlint-config": "^0.1.0",
|
|
58
|
-
"@systemfsoftware/
|
|
59
|
-
"@systemfsoftware/effect-
|
|
60
|
-
"@systemfsoftware/stryker-js-
|
|
61
|
-
"@systemfsoftware/stryker-js-typescript-checker": "^
|
|
62
|
-
"@systemfsoftware/stryker-plugins": "^
|
|
59
|
+
"@systemfsoftware/stryker-js-cli": "^6.0.0",
|
|
60
|
+
"@systemfsoftware/effect-gherkin-spec": "^4.0.1",
|
|
61
|
+
"@systemfsoftware/stryker-js-vitest-runner": "^4.0.0",
|
|
62
|
+
"@systemfsoftware/stryker-js-typescript-checker": "^5.0.0",
|
|
63
|
+
"@systemfsoftware/stryker-plugins": "^3.0.0",
|
|
64
|
+
"@systemfsoftware/stryker-test-contribution": "^2.0.0",
|
|
63
65
|
"@systemfsoftware/tsconfig": "^1.3.3",
|
|
64
|
-
"@systemfsoftware/stryker-test-contribution": "^1.1.2",
|
|
65
|
-
"@systemfsoftware/stryker-js-vitest-runner": "^2.1.0",
|
|
66
66
|
"@systemfsoftware/vitest-config": "^0.1.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|