@systemfsoftware/effect-daemon-spec 3.0.3 → 3.0.5
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 +17 -0
- package/dist/index.mjs +91 -64
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @systemfsoftware/effect-daemon-spec
|
|
2
2
|
|
|
3
|
+
## 3.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Re-released to propagate the effect-cell-types and stryker-js workflow-channel migration into their published dependency graphs; no package-local API change
|
|
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
|
+
- Updated dependencies:
|
|
12
|
+
- @systemfsoftware/effect-cell-types@6.0.0
|
|
13
|
+
|
|
14
|
+
## 3.0.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Refreshed builds on the platform-services dependency graph; the packages no longer reach for host builtins directly. No CLI flags or option names change.
|
|
19
|
+
|
|
3
20
|
## 3.0.3
|
|
4
21
|
|
|
5
22
|
### 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";
|
|
@@ -76,7 +76,10 @@ const MaxChildren = Schema.Int.pipe(Schema.check(Schema.isBetween({
|
|
|
76
76
|
minimum: 1,
|
|
77
77
|
maximum: MAX_CHILDREN_CEILING
|
|
78
78
|
})), Schema.brand("MaxChildren"));
|
|
79
|
-
Schema.Int.pipe(Schema.check(Schema.makeFilter((children) => children < 1 || children > 1e3
|
|
79
|
+
Schema.Int.pipe(Schema.check(Schema.makeFilter((children) => children < 1 || children > 1e3, { arbitrary: { candidate: {
|
|
80
|
+
weight: 20,
|
|
81
|
+
make: (fc) => fc.oneof(fc.integer({ max: 0 }), fc.integer({ min: 1001 }))
|
|
82
|
+
} } })));
|
|
80
83
|
Schema.decodeUnknownExit(ChildPolicyConfig);
|
|
81
84
|
Schema.decodeUnknownExit(LockPolicyConfig);
|
|
82
85
|
Schema.decodeUnknownExit(TickPolicyConfig);
|
|
@@ -421,53 +424,6 @@ const dynamic$1 = (spec) => Effect.gen(function* () {
|
|
|
421
424
|
return yield* buildDynamic(spec, health);
|
|
422
425
|
});
|
|
423
426
|
//#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
427
|
//#region src/internal/RestartDecision.schema.ts
|
|
472
428
|
/** @internal */
|
|
473
429
|
const RestartStrategy = Schema.Literals([
|
|
@@ -510,7 +466,25 @@ const DecideInputBase = Schema.Struct({
|
|
|
510
466
|
}))),
|
|
511
467
|
exitSuccess: Schema.Boolean,
|
|
512
468
|
intensityExceeded: Schema.Boolean
|
|
513
|
-
}).pipe(Schema.check(Schema.makeFilter(failedIndexAddressesAChild, {
|
|
469
|
+
}).pipe(Schema.check(Schema.makeFilter(failedIndexAddressesAChild, {
|
|
470
|
+
message: "failedIndex must be < totalChildren",
|
|
471
|
+
arbitrary: { candidate: {
|
|
472
|
+
weight: 20,
|
|
473
|
+
make: (fc) => fc.integer({
|
|
474
|
+
min: 1,
|
|
475
|
+
max: MAX_CHILDREN_CEILING
|
|
476
|
+
}).chain((totalChildren) => fc.record({
|
|
477
|
+
strategy: fc.constantFrom("one_for_one", "one_for_all", "rest_for_one"),
|
|
478
|
+
totalChildren: fc.constant(totalChildren),
|
|
479
|
+
failedIndex: fc.integer({
|
|
480
|
+
min: 0,
|
|
481
|
+
max: totalChildren - 1
|
|
482
|
+
}),
|
|
483
|
+
exitSuccess: fc.boolean(),
|
|
484
|
+
intensityExceeded: fc.boolean()
|
|
485
|
+
}))
|
|
486
|
+
} }
|
|
487
|
+
})));
|
|
514
488
|
/**
|
|
515
489
|
* The restart command. A `Schema.Class` rather than a `Schema.Struct` because `Workflow.make`
|
|
516
490
|
* takes the command's class as its first argument, and a struct carries no `identifier` and
|
|
@@ -520,7 +494,7 @@ const DecideInputBase = Schema.Struct({
|
|
|
520
494
|
/** @internal */
|
|
521
495
|
var DecideInput = class extends Schema.Class("DecideInput")(DecideInputBase) {};
|
|
522
496
|
//#endregion
|
|
523
|
-
//#region src/internal/
|
|
497
|
+
//#region src/internal/choose-restart-strategy.workflow.ts
|
|
524
498
|
/**
|
|
525
499
|
* The child indices a restart covers, by supervision strategy.
|
|
526
500
|
*
|
|
@@ -543,11 +517,58 @@ var RestartDecisionExhausted = class extends S.TaggedError()("Exhausted", {}) {
|
|
|
543
517
|
[RestartDecisionTypeId] = RestartDecisionTypeId;
|
|
544
518
|
};
|
|
545
519
|
/** @internal */
|
|
546
|
-
const
|
|
520
|
+
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
521
|
exitSuccess: false,
|
|
548
522
|
intensityExceeded: true
|
|
549
523
|
}, () => Result$1.fail(RestartDecisionExhausted.make())), Match$1.orElse(() => Result$1.succeed(RestartDecisionRestart.make({ indices: restartIndicesFor(command.strategy, command.failedIndex, command.totalChildren) })))));
|
|
550
524
|
//#endregion
|
|
525
|
+
//#region src/internal/IntensityWindow.ts
|
|
526
|
+
/** @internal */
|
|
527
|
+
const isWithinWindow = (now, windowMillis) => (t) => now - t <= windowMillis;
|
|
528
|
+
const keepWithin = (now, windowMillis) => (ts) => ts.filter(isWithinWindow(now, windowMillis));
|
|
529
|
+
/** @internal */
|
|
530
|
+
const pruneTimestamps = (ts, now, windowMillis) => keepWithin(now, windowMillis)(ts);
|
|
531
|
+
/** @internal */
|
|
532
|
+
const recordTimestamp = (ts, now, windowMillis) => [now, ...pruneTimestamps(ts, now, windowMillis)];
|
|
533
|
+
/** @internal */
|
|
534
|
+
const exceedsRestarts = (count, restarts) => count > restarts;
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/internal/Intensity.ts
|
|
537
|
+
/** @internal */
|
|
538
|
+
const neverExceeds = {
|
|
539
|
+
record: Effect.void,
|
|
540
|
+
isExceeded: Effect.succeed(false),
|
|
541
|
+
count: Effect.succeed(0)
|
|
542
|
+
};
|
|
543
|
+
/** @internal */
|
|
544
|
+
const make = (restarts, window) => Effect.gen(function* () {
|
|
545
|
+
const windowMillis = Duration.toMillis(window);
|
|
546
|
+
const timestamps = yield* Ref.make([]);
|
|
547
|
+
const prune = (now) => Ref.modify(timestamps, (ts) => {
|
|
548
|
+
const active = pruneTimestamps(ts, now, windowMillis);
|
|
549
|
+
return [active, active];
|
|
550
|
+
});
|
|
551
|
+
return {
|
|
552
|
+
record: Effect.gen(function* () {
|
|
553
|
+
const now = yield* Clock.currentTimeMillis;
|
|
554
|
+
yield* Ref.update(timestamps, (ts) => recordTimestamp(ts, now, windowMillis));
|
|
555
|
+
}),
|
|
556
|
+
isExceeded: Effect.gen(function* () {
|
|
557
|
+
const now = yield* Clock.currentTimeMillis;
|
|
558
|
+
const active = yield* prune(now);
|
|
559
|
+
return exceedsRestarts(active.length, restarts);
|
|
560
|
+
}),
|
|
561
|
+
count: Effect.gen(function* () {
|
|
562
|
+
const now = yield* Clock.currentTimeMillis;
|
|
563
|
+
return (yield* prune(now)).length;
|
|
564
|
+
})
|
|
565
|
+
};
|
|
566
|
+
});
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region src/internal/RaceForExit.ts
|
|
569
|
+
/** @internal */
|
|
570
|
+
const raceForExit = (fibers) => Effect.raceAll(fibers.map((f, idx) => Fiber.await(f).pipe(Effect.map((exit) => [idx, exit]))));
|
|
571
|
+
//#endregion
|
|
551
572
|
//#region src/internal/SupervisionEpoch.schema.ts
|
|
552
573
|
const EpochStepTypeId = Symbol.for("@systemfsoftware/effect-daemon/EpochStep");
|
|
553
574
|
/** @internal */
|
|
@@ -655,16 +676,22 @@ const handleRestart = (ctx, cause, onSignal) => Effect.gen(function* () {
|
|
|
655
676
|
* phase signatures hand the command to the read alone. Restarts are rare, so the allocation is
|
|
656
677
|
* paid only when a supervised child has actually died.
|
|
657
678
|
*/
|
|
658
|
-
const restartDescription = (spec) =>
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
679
|
+
const restartDescription = (spec) => Cell.layer({
|
|
680
|
+
read: (intensity) => Effect.andThen(intensity.record, intensity.isExceeded),
|
|
681
|
+
decode: (intensityExceeded) => Result.succeed({
|
|
682
|
+
strategy: spec.strategy,
|
|
683
|
+
totalChildren: spec.totalChildren,
|
|
684
|
+
failedIndex: spec.failedIndex,
|
|
685
|
+
exitSuccess: false,
|
|
686
|
+
intensityExceeded
|
|
687
|
+
}),
|
|
688
|
+
decide: chooseRestartStrategy,
|
|
689
|
+
encode: (outcome) => outcome,
|
|
690
|
+
write: (outcome) => Result.match(outcome, {
|
|
691
|
+
onFailure: () => handleExhausted(spec.ctx, spec.cause),
|
|
692
|
+
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)
|
|
693
|
+
})
|
|
694
|
+
});
|
|
668
695
|
const reopenHealthyAfterCooldown = (ctx) => Effect.andThen(ctx.health.healthy.open, Metric.update(Metric.withAttributes(healthStateGauge, {
|
|
669
696
|
daemon: ctx.name,
|
|
670
697
|
latch: "healthy"
|
|
@@ -722,7 +749,7 @@ const superviseChild = (ctx, child, idx) => Effect.gen(function* () {
|
|
|
722
749
|
if (!Exit.isSuccess(exit)) {
|
|
723
750
|
if (child.childPolicy.restart === "temporary") return StopEpoch.make();
|
|
724
751
|
if (yield* isChildIntensityBudgetDone(childIntensityOpt)) return StopEpoch.make();
|
|
725
|
-
return yield* Cell.
|
|
752
|
+
return yield* Cell.run(restartDescription({
|
|
726
753
|
strategy: "one_for_one",
|
|
727
754
|
failedIndex: idx,
|
|
728
755
|
totalChildren: ctx.booted.length,
|
|
@@ -767,7 +794,7 @@ const runGroup = (strategy, ctx) => Effect.gen(function* () {
|
|
|
767
794
|
if (failedBootedOpt.value.childPolicy.restart === "temporary") return StopEpoch.make();
|
|
768
795
|
const cIntForFailed = Option.flatten(Array.get(childIntensityTrackers, failedIdx));
|
|
769
796
|
if (yield* isChildIntensityBudgetDone(cIntForFailed)) return StopEpoch.make();
|
|
770
|
-
return yield* Cell.
|
|
797
|
+
return yield* Cell.run(restartDescription({
|
|
771
798
|
strategy,
|
|
772
799
|
failedIndex: failedIdx,
|
|
773
800
|
totalChildren: ctx.booted.length,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-daemon-spec",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.5",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@systemfsoftware/effect-cell-types": "^
|
|
40
|
+
"@systemfsoftware/effect-cell-types": "^6.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@effect/vitest": "4.0.0-rc.112",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"tsdown": "^0.22.14",
|
|
53
53
|
"typescript": "^7",
|
|
54
54
|
"vitest": "^4",
|
|
55
|
-
"@systemfsoftware/effect-schema-vite": "^2.0.2",
|
|
56
55
|
"@systemfsoftware/effect-gherkin-spec": "^4.0.0",
|
|
57
56
|
"@systemfsoftware/effect-schema-law": "^2.0.1",
|
|
57
|
+
"@systemfsoftware/effect-schema-vite": "^2.0.2",
|
|
58
|
+
"@systemfsoftware/stryker-js-cli": "^5.0.0",
|
|
59
|
+
"@systemfsoftware/stryker-js-typescript-checker": "^4.0.0",
|
|
58
60
|
"@systemfsoftware/oxlint-config": "^0.1.0",
|
|
59
|
-
"@systemfsoftware/
|
|
60
|
-
"@systemfsoftware/stryker-
|
|
61
|
-
"@systemfsoftware/
|
|
62
|
-
"@systemfsoftware/stryker-
|
|
63
|
-
"@systemfsoftware/
|
|
64
|
-
"@systemfsoftware/
|
|
65
|
-
"@systemfsoftware/vitest-config": "^0.1.0",
|
|
66
|
-
"@systemfsoftware/tsconfig": "^1.3.3"
|
|
61
|
+
"@systemfsoftware/stryker-js-vitest-runner": "^3.0.0",
|
|
62
|
+
"@systemfsoftware/stryker-plugins": "^2.0.2",
|
|
63
|
+
"@systemfsoftware/oxlint-plugin-cell-vocabulary": "^2.0.0",
|
|
64
|
+
"@systemfsoftware/stryker-test-contribution": "^1.1.3",
|
|
65
|
+
"@systemfsoftware/tsconfig": "^1.3.3",
|
|
66
|
+
"@systemfsoftware/vitest-config": "^0.1.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"effect": "^4.0.0-rc.112"
|