@mark1russell7/service 0.8.9 → 0.8.11

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/build/index.js CHANGED
@@ -2,8 +2,8 @@ import { a as recoverSpan, i as heartbeatDetection, n as asWindow, r as failSpan
2
2
  import { n as operationProblems, t as mayReissue } from "./operation-DF73RZOI.js";
3
3
  import { platformClock, realClock } from "./clock.js";
4
4
  import { a as limitRule, c as overCapacity, i as idleSpan, l as retryAfterSeconds, n as decide, o as limiterProblems, r as freeAt, s as longestRetryAfter, t as capacityOf, u as unitsOf } from "./policy-B23MY52l.js";
5
+ import { a as isExitCode, c as matchesMessage, d as poller, f as latch, i as embeddedProcess, l as nodeProcess, n as PROCESS_TRIGGERS, o as isExitSignal, r as UNCAUGHT_ORIGINS, s as isMessageShape, t as EXIT_SIGNALS, u as processPortOf } from "./process-7R9M29wN.js";
5
6
  import { a as lateHolds, l as takeOutside, n as countOf, r as millisecondsOf, s as ownStream, t as boundedMillisecondsOf } from "./knobs-BJcz6m01.js";
6
- import { a as isExitCode, c as matchesMessage, i as embeddedProcess, l as nodeProcess, n as PROCESS_TRIGGERS, o as isExitSignal, r as UNCAUGHT_ORIGINS, s as isMessageShape, t as EXIT_SIGNALS, u as processPortOf } from "./process-Oe0Abbsm.js";
7
7
  import { a as runUnit, c as untilAbort, i as retryOf, l as routePatternProblems, n as boundProblems, o as settleWithin, r as flights, s as sleeper, t as tracker } from "./requests-DD2ALv0_.js";
8
8
  import { backoffBand, backoffDelay, backoffProblems } from "./backoff.js";
9
9
  import { DRAIN_RULES, O04, O09, O10, O16 } from "./rules.js";
@@ -20,124 +20,6 @@ import { replay } from "@mark1russell7/algebra/replay";
20
20
  * zero.
21
21
  */
22
22
  const FORMAT = "mark1russell7.service/1";
23
- // src/latch.ts
24
- const ms = (amount) => valueIn(amount, "ms");
25
- /**
26
- * This function makes a latch. `tripped` is its state at the start: a readiness latch starts
27
- * tripped, and a liveness latch starts released. The latch starts `changed` each time it trips or
28
- * releases, and it gives each transition to `trace`. A debounce has the states `released` and
29
- * `tripped`. A window also has the states `failing` and `recovering`, while one of its timers runs.
30
- */
31
- const latch = (timing, clock, tripped, changed, trace) => {
32
- let state = tripped;
33
- let since = clock.now();
34
- let streak = 0;
35
- let fails = 0;
36
- let passes = 0;
37
- let failingSince = null;
38
- let passingSince = null;
39
- let failTimer = null;
40
- let passTimer = null;
41
- /** This function gives the name of the state, as the machine documents name it. */
42
- const named = () => state ? passingSince === null ? "tripped" : "recovering" : failingSince === null ? "released" : "failing";
43
- /** This function does one step of the machine, and gives its transition to the trace. */
44
- const step = (on, change) => {
45
- const from = named();
46
- change();
47
- trace?.(from, named(), on);
48
- };
49
- const set = (next) => {
50
- if (next === state) return;
51
- state = next;
52
- since = clock.now();
53
- changed();
54
- };
55
- const stopFail = () => {
56
- failTimer?.();
57
- failTimer = null;
58
- failingSince = null;
59
- };
60
- const stopPass = () => {
61
- passTimer?.();
62
- passTimer = null;
63
- passingSince = null;
64
- };
65
- const debounce = (result) => {
66
- if (timing.type !== "debounce") return;
67
- if (result.outcome === "ok") {
68
- passes += 1;
69
- fails = 0;
70
- if (state && passes >= timing.recoverAfter) set(false);
71
- } else {
72
- fails += 1;
73
- passes = 0;
74
- if (!state && fails >= timing.failAfter) set(true);
75
- }
76
- };
77
- const windowed = (result) => {
78
- if (timing.type !== "window") return;
79
- if (result.outcome === "ok") {
80
- stopFail();
81
- if (!state) return;
82
- if (timing.recoverAfter === void 0) {
83
- set(false);
84
- return;
85
- }
86
- if (passingSince !== null) return;
87
- const wait = ms(timing.recoverAfter);
88
- if (wait <= 0) {
89
- stopPass();
90
- set(false);
91
- return;
92
- }
93
- passingSince = result.at;
94
- passTimer = clock.after(wait, () => step("window.recovered", () => {
95
- passTimer = null;
96
- passingSince = null;
97
- set(false);
98
- }));
99
- return;
100
- }
101
- stopPass();
102
- if (state || failingSince !== null) return;
103
- const wait = ms(timing.failAfter);
104
- if (wait <= 0) {
105
- stopFail();
106
- set(true);
107
- return;
108
- }
109
- failingSince = result.at;
110
- failTimer = clock.after(wait, () => step("window.failed", () => {
111
- failTimer = null;
112
- failingSince = null;
113
- set(true);
114
- }));
115
- };
116
- return {
117
- get tripped() {
118
- return state;
119
- },
120
- get since() {
121
- return since;
122
- },
123
- get streak() {
124
- return streak;
125
- },
126
- record(result) {
127
- if (result.outcome === "indeterminate") return;
128
- const pass = result.outcome === "ok";
129
- step(pass ? "poll.ok" : "poll.fail", () => {
130
- streak = pass ? Math.max(0, streak) + 1 : Math.min(0, streak) - 1;
131
- debounce(result);
132
- windowed(result);
133
- });
134
- },
135
- stop() {
136
- stopFail();
137
- stopPass();
138
- }
139
- };
140
- };
141
23
  // src/metrics.ts
142
24
  /** These fractions of the timeout of a poll are the bounds of its histogram. */
143
25
  const DURATION_FRACTIONS = [
@@ -245,154 +127,6 @@ const meter = () => {
245
127
  metrics
246
128
  };
247
129
  };
248
- // src/poller.ts
249
- const message$1 = (error) => error instanceof Error ? error.message : String(error);
250
- /**
251
- * This function makes a poller. The loop is on a fixed delay from the start of each poll. Thus the
252
- * next poll starts one interval after the current poll starts, with the jitter (±20 % is 0.2).
253
- * The timing algebra of the declaration uses this model.
254
- *
255
- * Each poll makes a new measurement. While a use of the check is pending, the poller does not
256
- * start the check again. Such a poll fails at once with the same cause, and the sequence of
257
- * failures continues.
258
- */
259
- const poller = (options) => {
260
- const { clock, poll, run } = options;
261
- const interval = valueIn(poll.interval, "ms");
262
- const timeout = valueIn(poll.timeout, "ms");
263
- let last = null;
264
- let next = null;
265
- let stopped = false;
266
- let looping = false;
267
- let pending = null;
268
- const active = /* @__PURE__ */ new Set();
269
- /** This function gives the name of the state, as the machine document of the poller names it. */
270
- const named = () => stopped ? "stopped" : pending !== null ? pending.late ? "hung" : "calling" : looping ? "waiting" : "idle";
271
- const step = (on, change) => {
272
- const from = named();
273
- change();
274
- options.trace?.(from, named(), on);
275
- };
276
- const result = (outcome, started, fields = {}) => ({
277
- outcome,
278
- at: clock.now(),
279
- took: clock.now() - started,
280
- cause: fields.cause ?? null,
281
- timedOut: fields.timedOut ?? false,
282
- thrown: fields.thrown ?? false,
283
- forced: fields.forced ?? false
284
- });
285
- const once = () => {
286
- const started = clock.now();
287
- if (options.forced()) return Promise.resolve(result("error", started, {
288
- cause: "the force-fail list names it",
289
- forced: true
290
- }));
291
- if (pending !== null) {
292
- const cause = `its call of ${Math.round(started - pending.since)} ms ago is still pending`;
293
- return Promise.resolve(result("error", started, { cause }));
294
- }
295
- const controller = new AbortController();
296
- return new Promise((resolve) => {
297
- let done = false;
298
- const finish = (value) => {
299
- if (done) return;
300
- done = true;
301
- active.delete(abandon);
302
- cancel();
303
- resolve(value);
304
- };
305
- const abandon = () => {
306
- controller.abort();
307
- finish(result("error", started, { cause: "the runtime stopped" }));
308
- };
309
- active.add(abandon);
310
- const call = {
311
- since: started,
312
- late: false
313
- };
314
- pending = call;
315
- const cancel = clock.after(timeout, () => {
316
- controller.abort();
317
- step("timeout", () => {
318
- if (pending === call) call.late = true;
319
- });
320
- finish(result("error", started, {
321
- cause: `no answer in ${timeout} ms`,
322
- timedOut: true
323
- }));
324
- });
325
- const settled = () => {
326
- if (pending !== call) return;
327
- step(call.late ? "late-answer" : "answer", () => {
328
- pending = null;
329
- });
330
- };
331
- let answer;
332
- try {
333
- answer = Promise.resolve(run(controller.signal));
334
- } catch (error) {
335
- answer = Promise.reject(error);
336
- }
337
- answer.then((value) => {
338
- settled();
339
- const outcome = value ?? "ok";
340
- finish(result(outcome, started, outcome === "ok" ? {} : { cause: `the check gave ${outcome}` }));
341
- }, (error) => {
342
- settled();
343
- finish(result("error", started, {
344
- cause: message$1(error),
345
- thrown: true
346
- }));
347
- });
348
- });
349
- };
350
- const handle = (value) => {
351
- last = value;
352
- if (!stopped) options.record(value);
353
- return value;
354
- };
355
- const jittered = () => interval * (1 + poll.jitter * (2 * options.random() - 1));
356
- const tick = () => {
357
- next = null;
358
- if (stopped) return;
359
- let polled;
360
- step("tick", () => {
361
- next = clock.after(jittered(), tick);
362
- polled = once();
363
- });
364
- polled.then(handle);
365
- };
366
- return {
367
- get last() {
368
- return last;
369
- },
370
- pollNow: () => {
371
- let polled;
372
- step("sweep", () => {
373
- polled = once();
374
- });
375
- return polled.then(handle);
376
- },
377
- start(delay) {
378
- if (stopped || next !== null) return;
379
- step("start", () => {
380
- looping = true;
381
- next = clock.after(Math.max(0, delay), tick);
382
- });
383
- },
384
- jittered,
385
- stop() {
386
- if (stopped) return;
387
- step("stop", () => {
388
- stopped = true;
389
- next?.();
390
- next = null;
391
- });
392
- for (const abandon of [...active]) abandon();
393
- }
394
- };
395
- };
396
130
  // src/health.ts
397
131
  /**
398
132
  * This function makes the runtime of a declaration. The service has no defaults of its own: each