@yaks/effects 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +979 -2
- package/_dist/docs.d.ts +10 -0
- package/_dist/docs.d.ts.map +1 -0
- package/_dist/enqueue.d.ts +12 -0
- package/_dist/enqueue.d.ts.map +1 -0
- package/_dist/expire.d.ts +31 -0
- package/_dist/expire.d.ts.map +1 -0
- package/_dist/invocation.d.ts +36 -0
- package/_dist/invocation.d.ts.map +1 -0
- package/_dist/lease.d.ts +98 -0
- package/_dist/lease.d.ts.map +1 -0
- package/_dist/mod.d.ts +89 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/outage.d.ts +48 -0
- package/_dist/outage.d.ts.map +1 -0
- package/_dist/pool.d.ts +148 -0
- package/_dist/pool.d.ts.map +1 -0
- package/_dist/provisional.d.ts +8 -0
- package/_dist/provisional.d.ts.map +1 -0
- package/_dist/ready.d.ts +3 -0
- package/_dist/ready.d.ts.map +1 -0
- package/_dist/registration.d.ts +17 -0
- package/_dist/registration.d.ts.map +1 -0
- package/_dist/registry.d.ts +153 -0
- package/_dist/registry.d.ts.map +1 -0
- package/_dist/tools.d.ts +21 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/trace.d.ts +63 -0
- package/_dist/trace.d.ts.map +1 -0
- package/_dist/views.d.ts +15 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +11 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/worker.d.ts +19 -0
- package/_dist/worker.d.ts.map +1 -0
- package/_dist/write.d.ts +25 -0
- package/_dist/write.d.ts.map +1 -0
- package/cleanup.js +75 -0
- package/cleanup.js.map +1 -0
- package/cleanup.ts +83 -0
- package/deno.json +1 -0
- package/docs.js +13 -0
- package/docs.js.map +1 -0
- package/docs.ts +13 -0
- package/enqueue.js +71 -0
- package/enqueue.js.map +1 -0
- package/enqueue.ts +86 -0
- package/expire.js +225 -0
- package/expire.js.map +1 -0
- package/expire.ts +244 -0
- package/invocation.js +245 -0
- package/invocation.js.map +1 -0
- package/invocation.ts +250 -0
- package/lease.js +343 -0
- package/lease.js.map +1 -0
- package/lease.ts +444 -0
- package/mod.js +89 -0
- package/mod.js.map +1 -0
- package/mod.ts +92 -0
- package/outage.js +77 -0
- package/outage.js.map +1 -0
- package/outage.ts +84 -0
- package/package.json +52 -4
- package/page.js +315 -0
- package/page.js.map +1 -0
- package/page.ts +524 -0
- package/pool.js +1474 -0
- package/pool.js.map +1 -0
- package/pool.ts +1635 -0
- package/provisional.js +20 -0
- package/provisional.js.map +1 -0
- package/provisional.ts +26 -0
- package/ready.js +48 -0
- package/ready.js.map +1 -0
- package/ready.ts +93 -0
- package/registration.js +21 -0
- package/registration.js.map +1 -0
- package/registration.ts +43 -0
- package/registry.js +872 -0
- package/registry.js.map +1 -0
- package/registry.ts +1196 -0
- package/tools.js +182 -0
- package/tools.js.map +1 -0
- package/tools.ts +229 -0
- package/trace.js +167 -0
- package/trace.js.map +1 -0
- package/trace.ts +217 -0
- package/views.js +18 -0
- package/views.js.map +1 -0
- package/views.ts +18 -0
- package/vocab.js +18 -0
- package/vocab.js.map +1 -0
- package/vocab.json +364 -0
- package/vocab.ts +20 -0
- package/worker.js +114 -0
- package/worker.js.map +1 -0
- package/worker.ts +146 -0
- package/write.js +38 -0
- package/write.js.map +1 -0
- package/write.ts +60 -0
package/page.ts
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page the browsing app's sidebar offers as Effects: the processes
|
|
3
|
+
* working the effect pool, how busy each is and what it is running, how fast
|
|
4
|
+
* runs end, and the runs owed behind them, by handler. It moves as the
|
|
5
|
+
* workers say themselves, every fifteen seconds (./worker.ts `SAY`).
|
|
6
|
+
*
|
|
7
|
+
* Where each number comes from:
|
|
8
|
+
* - workers, what each is running, runs a second and how busy each is: the
|
|
9
|
+
* `worker` row every process working the pool writes on itself
|
|
10
|
+
* (./worker.ts). A worker is up while that row is fresh;
|
|
11
|
+
* - running, waiting, retrying and failed by handler: the `effect` rows
|
|
12
|
+
* themselves, tallied by handler (./pool.ts), for every effect the
|
|
13
|
+
* vocabulary declares, each named by its `_effect` row (@yaks/vocab), so
|
|
14
|
+
* one owed nothing still shows.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import {
|
|
19
|
+
createElement as h,
|
|
20
|
+
type JSX,
|
|
21
|
+
type ReactNode,
|
|
22
|
+
useEffect,
|
|
23
|
+
useState,
|
|
24
|
+
} from 'react'
|
|
25
|
+
import {
|
|
26
|
+
type Answer,
|
|
27
|
+
type Bundle,
|
|
28
|
+
effectEid,
|
|
29
|
+
type Io,
|
|
30
|
+
mention,
|
|
31
|
+
type Props,
|
|
32
|
+
useNamed,
|
|
33
|
+
type View,
|
|
34
|
+
} from '@yaks/inspect'
|
|
35
|
+
import { Head, Loading, Meter, Metrics, Section, Spark, Table } from '@yaks/ui'
|
|
36
|
+
import { effectsIn } from '@yaks/vocab'
|
|
37
|
+
import { rate, said, SAY, type Worker } from './worker.js'
|
|
38
|
+
|
|
39
|
+
/** How long a worker may say nothing before it reads as silent (ms): two of
|
|
40
|
+
* its turns to say something. */
|
|
41
|
+
export let QUIET = 2 * SAY
|
|
42
|
+
|
|
43
|
+
/** How long a silent worker is still shown (ms); past this it is long gone,
|
|
44
|
+
* whatever its process row says. */
|
|
45
|
+
export let FORGOTTEN = 10 * 60_000
|
|
46
|
+
|
|
47
|
+
/** What a process is called: the name its unit gave it, or what it runs. */
|
|
48
|
+
/// called('deno work --process yak-work --config x') -> 'yak-work'
|
|
49
|
+
/// called('deno browse --config x') -> 'browse'
|
|
50
|
+
/// called() -> 'process'
|
|
51
|
+
export let called = (command = ''): string => {
|
|
52
|
+
let words = command.split(/\s+/).filter(Boolean)
|
|
53
|
+
return command.match(/--process[ =](\S+)/)?.[1] ?? words[1] ?? words[0] ??
|
|
54
|
+
'process'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** How long something has lasted, in its two largest units. */
|
|
58
|
+
/// lasted(12_400) -> '12s'
|
|
59
|
+
/// lasted(192_000) -> '3m 12s'
|
|
60
|
+
/// lasted(3 * 3_600_000 + 60_000) -> '3h 1m'
|
|
61
|
+
/// lasted(50 * 3_600_000) -> '2d 2h'
|
|
62
|
+
export let lasted = (ms: number): string => {
|
|
63
|
+
let s = Math.max(0, Math.floor(ms / 1000))
|
|
64
|
+
let d = Math.floor(s / 86_400), h = Math.floor(s / 3600) % 24
|
|
65
|
+
let m = Math.floor(s / 60) % 60
|
|
66
|
+
return d
|
|
67
|
+
? `${d}d ${h}h`
|
|
68
|
+
: h
|
|
69
|
+
? `${h}h ${m}m`
|
|
70
|
+
: m
|
|
71
|
+
? `${m}m ${s % 60}s`
|
|
72
|
+
: `${s}s`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Runs a second, as a person reads them. */
|
|
76
|
+
/// perSecond(0) -> '0'
|
|
77
|
+
/// perSecond(0.4) -> '0.4'
|
|
78
|
+
/// perSecond(12.6) -> '13'
|
|
79
|
+
/// perSecond(1234) -> '1,234'
|
|
80
|
+
export let perSecond = (n: number): string =>
|
|
81
|
+
n == 0 ? '0' : n < 10 ? n.toFixed(1) : Math.round(n).toLocaleString('en-US')
|
|
82
|
+
|
|
83
|
+
/** Several workers' histories as one, second by second, their newest seconds
|
|
84
|
+
* lined up. */
|
|
85
|
+
/// together([[1, 2, 3], [0, 1]]) -> [1, 2, 4]
|
|
86
|
+
/// together([]) -> []
|
|
87
|
+
export let together = (histories: number[][]): number[] => {
|
|
88
|
+
let n = Math.max(0, ...histories.map((h) => h.length))
|
|
89
|
+
return Array.from(
|
|
90
|
+
{ length: n },
|
|
91
|
+
(_, i) => histories.reduce((sum, h) => sum + (h[h.length - n + i] ?? 0), 0),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A worker, as the page shows it. */
|
|
96
|
+
export type Seen = {
|
|
97
|
+
eid: string
|
|
98
|
+
name: string
|
|
99
|
+
pid?: number
|
|
100
|
+
/** when its process started, ISO-8601 */
|
|
101
|
+
born?: string
|
|
102
|
+
w: Worker
|
|
103
|
+
/** how long since it last said anything (ms) */
|
|
104
|
+
silent: number
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The workers worth showing, by name: every one that said something in the
|
|
108
|
+
* last {@link FORGOTTEN}, with how long ago. */
|
|
109
|
+
/// let w = (eid: string, at: string) => ({ entity: { eid }, worker: { at }, process: { pid: 7, command: 'deno work --process yak-work' } })
|
|
110
|
+
/// let now = Date.parse('2026-01-01T00:00:10Z')
|
|
111
|
+
/// workers([w('a', '2026-01-01T00:00:09Z'), w('b', '2026-01-01T00:00:00Z'), w('c', '2025-01-01T00:00:00Z')], now).map((s) => [s.eid, s.name, s.silent])
|
|
112
|
+
/// -> [['a', 'yak-work', 1000], ['b', 'yak-work', 10000]]
|
|
113
|
+
export let workers = (rows: Bundle[], now: number): Seen[] =>
|
|
114
|
+
rows.flatMap((b) => {
|
|
115
|
+
let w = said(b)
|
|
116
|
+
if (!w) return []
|
|
117
|
+
let silent = Math.max(0, now - Date.parse(w.at))
|
|
118
|
+
if (!(silent <= FORGOTTEN)) return []
|
|
119
|
+
let p = (b.process ?? {}) as { pid?: number; command?: string }
|
|
120
|
+
let born = (b.created as { at?: string } | undefined)?.at
|
|
121
|
+
return [{
|
|
122
|
+
eid: b.entity.eid,
|
|
123
|
+
name: called(p.command),
|
|
124
|
+
pid: p.pid,
|
|
125
|
+
born,
|
|
126
|
+
w,
|
|
127
|
+
silent,
|
|
128
|
+
}]
|
|
129
|
+
}).sort((a, b) =>
|
|
130
|
+
a.name.localeCompare(b.name) || (a.pid ?? 0) - (b.pid ?? 0) ||
|
|
131
|
+
a.eid.localeCompare(b.eid)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
/** The runs owed to one handler. */
|
|
135
|
+
export type Owed = {
|
|
136
|
+
handler: string
|
|
137
|
+
/** claimed by a worker, so going now */
|
|
138
|
+
running: number
|
|
139
|
+
/** owed and not yet claimed, due or backing off */
|
|
140
|
+
waiting: number
|
|
141
|
+
/** of the owed, those that failed before and will be tried again */
|
|
142
|
+
retrying: number
|
|
143
|
+
/** spent their tries, left for a person */
|
|
144
|
+
failed: number
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
type Tally = Record<string, number> | undefined
|
|
148
|
+
|
|
149
|
+
/** The runs owed by handler, from the `effect` rows' tallies: every handler
|
|
150
|
+
* owed something, and each of `declared` though it is owed nothing. The
|
|
151
|
+
* busiest first, then the most failed, then by name. */
|
|
152
|
+
/// handlers({ owed: { a: 3, b: 1 }, claimed: { a: 1 }, retrying: { b: 1 }, failed: { c: 2, b: 1 } }).map((o) => Object.values(o))
|
|
153
|
+
/// -> [['a', 1, 2, 0, 0], ['b', 0, 1, 1, 1], ['c', 0, 0, 0, 2]]
|
|
154
|
+
/// handlers({}, ['z']) -> [{ handler: 'z', running: 0, waiting: 0, retrying: 0, failed: 0 }]
|
|
155
|
+
export let handlers = (
|
|
156
|
+
t: { owed?: Tally; claimed?: Tally; retrying?: Tally; failed?: Tally },
|
|
157
|
+
declared: string[] = [],
|
|
158
|
+
): Owed[] => {
|
|
159
|
+
let n = (x: Tally, k: string) => x?.[k] ?? 0
|
|
160
|
+
let names = new Set([
|
|
161
|
+
...declared,
|
|
162
|
+
...[t.owed, t.claimed, t.retrying, t.failed].flatMap((x) =>
|
|
163
|
+
Object.keys(x ?? {})
|
|
164
|
+
),
|
|
165
|
+
])
|
|
166
|
+
return [...names].map((handler) => ({
|
|
167
|
+
handler,
|
|
168
|
+
running: n(t.claimed, handler),
|
|
169
|
+
waiting: Math.max(0, n(t.owed, handler) - n(t.claimed, handler)),
|
|
170
|
+
retrying: n(t.retrying, handler),
|
|
171
|
+
failed: n(t.failed, handler),
|
|
172
|
+
})).sort((a, b) =>
|
|
173
|
+
b.running + b.waiting - a.running - a.waiting || b.failed - a.failed ||
|
|
174
|
+
a.handler.localeCompare(b.handler)
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// What the page asks: every worker still running with its process, and the
|
|
179
|
+
// effect rows owed, tallied by handler four ways.
|
|
180
|
+
let asks = (_e: Bundle, io: Io) => {
|
|
181
|
+
let has = (c: string) => !!io.vocab.comp(c)
|
|
182
|
+
return {
|
|
183
|
+
workers: `.worker${has('exit') ? '&!exit' : ''}` +
|
|
184
|
+
['process', 'created'].filter(has).map((c) => `&?${c}`).join('') +
|
|
185
|
+
'&.limit=100',
|
|
186
|
+
owed: '.effect.state=pending&.tally=effect.handler',
|
|
187
|
+
claimed: '.effect.state=pending&.effect.lease_owner&.tally=effect.handler',
|
|
188
|
+
retrying: '.effect.state=pending&.effect.error&.tally=effect.handler',
|
|
189
|
+
failed: '.effect.state=failed&.tally=effect.handler',
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// The clock the page reads, moving every second while it is drawn.
|
|
194
|
+
let useNow = (every = 1000) => {
|
|
195
|
+
let [now, set] = useState(() => Date.now())
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
let timer = setInterval(() => set(Date.now()), every)
|
|
198
|
+
return () => clearInterval(timer)
|
|
199
|
+
}, [every])
|
|
200
|
+
return now
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let { Body, Cell, Heading, Row } = Table
|
|
204
|
+
|
|
205
|
+
let heads = (...names: (string | [string, string])[]) =>
|
|
206
|
+
h(
|
|
207
|
+
Table.Head,
|
|
208
|
+
{},
|
|
209
|
+
h(
|
|
210
|
+
Row,
|
|
211
|
+
{},
|
|
212
|
+
names.map((n) =>
|
|
213
|
+
typeof n == 'string'
|
|
214
|
+
? h(Heading, { key: n }, n)
|
|
215
|
+
: h(Heading, { key: n[0], mod: n[1] }, n[0])
|
|
216
|
+
),
|
|
217
|
+
),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
// A count that opens the runs it counts; nothing where there are none.
|
|
221
|
+
let count = (io: Io, n: number, query: string) =>
|
|
222
|
+
n ? h('a', { href: io.find(query) }, n.toLocaleString('en-US')) : ''
|
|
223
|
+
|
|
224
|
+
let stat = (
|
|
225
|
+
value: string,
|
|
226
|
+
label: string,
|
|
227
|
+
mod?: string,
|
|
228
|
+
note?: ReactNode,
|
|
229
|
+
) =>
|
|
230
|
+
h(
|
|
231
|
+
Metrics.Item,
|
|
232
|
+
{},
|
|
233
|
+
h(Metrics.Value, { mod }, value),
|
|
234
|
+
h(Metrics.Label, {}, label),
|
|
235
|
+
note ? h(Metrics.Note, {}, note) : null,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
let percent = (n: number) => `${Math.round(n * 100)}%`
|
|
239
|
+
|
|
240
|
+
// The workers, one a row: how busy, how fast, how much, and how long up.
|
|
241
|
+
let Workers = ({ io, seen, now }: { io: Io; seen: Seen[]; now: number }) =>
|
|
242
|
+
h(
|
|
243
|
+
Section,
|
|
244
|
+
{},
|
|
245
|
+
h(Section.Title, {}, 'Workers'),
|
|
246
|
+
h(
|
|
247
|
+
Section.Sub,
|
|
248
|
+
{},
|
|
249
|
+
'Each process working the pool. Busy is the share of a core it used; loop is how late its thread ran a timer, which climbs as its event loop fills.',
|
|
250
|
+
),
|
|
251
|
+
seen.length
|
|
252
|
+
? h(
|
|
253
|
+
Table,
|
|
254
|
+
{ cols: [null, null, 'num', null, 'num', 'num', 'num', null] },
|
|
255
|
+
heads(
|
|
256
|
+
'worker',
|
|
257
|
+
'busy',
|
|
258
|
+
['loop', 'num'],
|
|
259
|
+
'runs a second',
|
|
260
|
+
['running', 'num'],
|
|
261
|
+
['finished', 'num'],
|
|
262
|
+
['errors', 'num'],
|
|
263
|
+
'up',
|
|
264
|
+
),
|
|
265
|
+
h(
|
|
266
|
+
Body,
|
|
267
|
+
{},
|
|
268
|
+
seen.map(({ eid, name, pid, born, w, silent }) =>
|
|
269
|
+
h(
|
|
270
|
+
Row,
|
|
271
|
+
{ key: eid, 'data-worker': eid },
|
|
272
|
+
h(
|
|
273
|
+
Cell,
|
|
274
|
+
{},
|
|
275
|
+
h('a', { href: io.link(eid) }, name),
|
|
276
|
+
pid ? ` ${pid}` : '',
|
|
277
|
+
),
|
|
278
|
+
h(
|
|
279
|
+
Cell,
|
|
280
|
+
{},
|
|
281
|
+
w.cpu == null ? '' : [
|
|
282
|
+
h(Meter, { value: w.cpu, width: 10 }),
|
|
283
|
+
' ',
|
|
284
|
+
percent(w.cpu),
|
|
285
|
+
],
|
|
286
|
+
),
|
|
287
|
+
h(Cell, { mod: 'num' }, w.lag == null ? '' : `${w.lag} ms`),
|
|
288
|
+
h(
|
|
289
|
+
Cell,
|
|
290
|
+
{},
|
|
291
|
+
h(Spark, { values: w.history.slice(-20) }),
|
|
292
|
+
` ${perSecond(rate(w.history))}`,
|
|
293
|
+
),
|
|
294
|
+
h(Cell, { mod: 'num' }, String(w.running)),
|
|
295
|
+
h(Cell, { mod: 'num' }, w.ran.toLocaleString('en-US')),
|
|
296
|
+
h(Cell, { mod: 'num' }, w.errors.toLocaleString('en-US')),
|
|
297
|
+
h(
|
|
298
|
+
Cell,
|
|
299
|
+
{ 'data-silent': silent >= QUIET ? '' : undefined },
|
|
300
|
+
silent >= QUIET
|
|
301
|
+
? `silent ${lasted(silent)}`
|
|
302
|
+
: born
|
|
303
|
+
? lasted(now - Date.parse(born))
|
|
304
|
+
: '',
|
|
305
|
+
),
|
|
306
|
+
)
|
|
307
|
+
),
|
|
308
|
+
),
|
|
309
|
+
)
|
|
310
|
+
: h(
|
|
311
|
+
Section.Sub,
|
|
312
|
+
{ role: 'status' },
|
|
313
|
+
'No process is working the pool, so nothing owed runs until one starts.',
|
|
314
|
+
),
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
// Every run going in a worker that is up, the longest first.
|
|
318
|
+
let Running = ({ io, up, now }: { io: Io; up: Seen[]; now: number }) => {
|
|
319
|
+
let runs = up.flatMap((s) => s.w.runs.map((r) => ({ ...r, by: s })))
|
|
320
|
+
.sort((a, b) => a.since.localeCompare(b.since))
|
|
321
|
+
let unlisted = up.reduce((n, s) => n + s.w.running - s.w.runs.length, 0)
|
|
322
|
+
useNamed(io, runs.map((r) => r.target))
|
|
323
|
+
return h(
|
|
324
|
+
Section,
|
|
325
|
+
{},
|
|
326
|
+
h(
|
|
327
|
+
Section.Title,
|
|
328
|
+
{},
|
|
329
|
+
'Running now',
|
|
330
|
+
' ',
|
|
331
|
+
h(Section.Count, {}, String(runs.length + unlisted)),
|
|
332
|
+
),
|
|
333
|
+
runs.length
|
|
334
|
+
? h(
|
|
335
|
+
Table,
|
|
336
|
+
{ cols: [null, null, null, 'num'] },
|
|
337
|
+
heads('handler', 'for', 'worker', ['running for', 'num']),
|
|
338
|
+
h(
|
|
339
|
+
Body,
|
|
340
|
+
{},
|
|
341
|
+
runs.map((r) =>
|
|
342
|
+
h(
|
|
343
|
+
Row,
|
|
344
|
+
{ key: r.run, 'data-run': r.run },
|
|
345
|
+
h(Cell, {}, r.handler),
|
|
346
|
+
h(Cell, {}, mention(io, r.target)),
|
|
347
|
+
h(Cell, {}, r.by.name),
|
|
348
|
+
h(Cell, { mod: 'num' }, lasted(now - Date.parse(r.since))),
|
|
349
|
+
)
|
|
350
|
+
),
|
|
351
|
+
unlisted > 0
|
|
352
|
+
? h(
|
|
353
|
+
Row,
|
|
354
|
+
{ mod: 'quiet' },
|
|
355
|
+
h(Cell, {}, `and ${unlisted.toLocaleString('en-US')} more`),
|
|
356
|
+
)
|
|
357
|
+
: null,
|
|
358
|
+
),
|
|
359
|
+
)
|
|
360
|
+
: h(Section.Sub, {}, 'Nothing is running.'),
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// What each handler is owed: going, waiting, retrying and failed, each a
|
|
365
|
+
// link to those runs; its name, a link to its declaration. One owed nothing
|
|
366
|
+
// steps back.
|
|
367
|
+
let Handlers = ({ io, owed }: { io: Io; owed: Owed[] }) => {
|
|
368
|
+
let of = (handler: string, rest: string) =>
|
|
369
|
+
`.effect.handler=${handler}&${rest}&?effect`
|
|
370
|
+
return h(
|
|
371
|
+
Section,
|
|
372
|
+
{},
|
|
373
|
+
h(Section.Title, {}, 'By handler'),
|
|
374
|
+
h(
|
|
375
|
+
Section.Sub,
|
|
376
|
+
{},
|
|
377
|
+
'The runs each declared effect is owed. Retrying ones failed before and wait out their backoff; failed ones spent their tries and wait for a person.',
|
|
378
|
+
),
|
|
379
|
+
owed.length
|
|
380
|
+
? h(
|
|
381
|
+
Table,
|
|
382
|
+
{ cols: [null, 'num', 'num', 'num', 'num'] },
|
|
383
|
+
heads(
|
|
384
|
+
'handler',
|
|
385
|
+
['running', 'num'],
|
|
386
|
+
['waiting', 'num'],
|
|
387
|
+
['retrying', 'num'],
|
|
388
|
+
['failed', 'num'],
|
|
389
|
+
),
|
|
390
|
+
h(
|
|
391
|
+
Body,
|
|
392
|
+
{},
|
|
393
|
+
owed.map((o) =>
|
|
394
|
+
h(
|
|
395
|
+
Row,
|
|
396
|
+
{
|
|
397
|
+
key: o.handler,
|
|
398
|
+
'data-handler': o.handler,
|
|
399
|
+
mod: o.running + o.waiting + o.failed ? undefined : 'quiet',
|
|
400
|
+
},
|
|
401
|
+
h(
|
|
402
|
+
Cell,
|
|
403
|
+
{},
|
|
404
|
+
h(
|
|
405
|
+
'a',
|
|
406
|
+
{ href: io.link(effectEid(io.vocab, o.handler)) },
|
|
407
|
+
o.handler,
|
|
408
|
+
),
|
|
409
|
+
),
|
|
410
|
+
h(
|
|
411
|
+
Cell,
|
|
412
|
+
{ mod: 'num' },
|
|
413
|
+
count(io, o.running, of(o.handler, '.effect.lease_owner')),
|
|
414
|
+
),
|
|
415
|
+
h(
|
|
416
|
+
Cell,
|
|
417
|
+
{ mod: 'num' },
|
|
418
|
+
count(
|
|
419
|
+
io,
|
|
420
|
+
o.waiting,
|
|
421
|
+
of(o.handler, '.effect.state=pending&!effect.lease_owner'),
|
|
422
|
+
),
|
|
423
|
+
),
|
|
424
|
+
h(
|
|
425
|
+
Cell,
|
|
426
|
+
{ mod: 'num' },
|
|
427
|
+
count(
|
|
428
|
+
io,
|
|
429
|
+
o.retrying,
|
|
430
|
+
of(o.handler, '.effect.state=pending&.effect.error'),
|
|
431
|
+
),
|
|
432
|
+
),
|
|
433
|
+
h(
|
|
434
|
+
Cell,
|
|
435
|
+
{ mod: 'num' },
|
|
436
|
+
count(io, o.failed, of(o.handler, '.effect.state=failed')),
|
|
437
|
+
),
|
|
438
|
+
)
|
|
439
|
+
),
|
|
440
|
+
),
|
|
441
|
+
)
|
|
442
|
+
: h(Section.Sub, {}, 'Nothing is owed: every run has ended.'),
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
let waiting = (got: Answer | undefined, what: string) =>
|
|
447
|
+
got?.error
|
|
448
|
+
? h(Section.Sub, { role: 'alert' }, got.error)
|
|
449
|
+
: !got?.ready
|
|
450
|
+
? h(Loading, {}, `Loading ${what}…`)
|
|
451
|
+
: null
|
|
452
|
+
|
|
453
|
+
/** The page. */
|
|
454
|
+
export let EffectsPage = ({ got, io }: Props): JSX.Element => {
|
|
455
|
+
let now = useNow()
|
|
456
|
+
let seen = workers(got.workers?.rows ?? [], now)
|
|
457
|
+
let up = seen.filter((s) => s.silent < QUIET)
|
|
458
|
+
let owed = handlers({
|
|
459
|
+
owed: got.owed?.tally,
|
|
460
|
+
claimed: got.claimed?.tally,
|
|
461
|
+
retrying: got.retrying?.tally,
|
|
462
|
+
failed: got.failed?.tally,
|
|
463
|
+
}, io.vocab.docs.flatMap((d) => effectsIn(d).map((x) => x.name)))
|
|
464
|
+
let total = (k: 'waiting' | 'retrying' | 'failed') =>
|
|
465
|
+
owed.reduce((n, o) => n + o[k], 0)
|
|
466
|
+
let history = together(up.map((s) => s.w.history))
|
|
467
|
+
let speed = rate(history)
|
|
468
|
+
let running = up.reduce((n, s) => n + s.w.running, 0)
|
|
469
|
+
let silent = seen.length - up.length
|
|
470
|
+
let left = total('waiting'), retrying = total('retrying')
|
|
471
|
+
let failed = total('failed')
|
|
472
|
+
return h(
|
|
473
|
+
'article',
|
|
474
|
+
{ 'data-effects': '' },
|
|
475
|
+
h(
|
|
476
|
+
Head,
|
|
477
|
+
{},
|
|
478
|
+
h(Head.Title, {}, 'Effects'),
|
|
479
|
+
h(
|
|
480
|
+
Head.Sub,
|
|
481
|
+
{},
|
|
482
|
+
'The work a write leaves behind, and the processes doing it: how many are up, how busy each is, what each is running and how fast runs end, then what waits behind them.',
|
|
483
|
+
),
|
|
484
|
+
),
|
|
485
|
+
waiting(got.workers, 'the workers') ?? [
|
|
486
|
+
h(
|
|
487
|
+
Metrics,
|
|
488
|
+
{},
|
|
489
|
+
stat(
|
|
490
|
+
String(up.length),
|
|
491
|
+
up.length == 1 ? 'worker up' : 'workers up',
|
|
492
|
+
!up.length && left ? 'negative' : undefined,
|
|
493
|
+
silent ? `${silent} silent` : null,
|
|
494
|
+
),
|
|
495
|
+
stat(String(running), 'running now'),
|
|
496
|
+
stat(
|
|
497
|
+
perSecond(speed),
|
|
498
|
+
'runs a second',
|
|
499
|
+
undefined,
|
|
500
|
+
h(Spark, { values: history }),
|
|
501
|
+
),
|
|
502
|
+
stat(
|
|
503
|
+
left.toLocaleString('en-US'),
|
|
504
|
+
'waiting',
|
|
505
|
+
undefined,
|
|
506
|
+
retrying ? `${retrying.toLocaleString('en-US')} retrying` : null,
|
|
507
|
+
),
|
|
508
|
+
stat(
|
|
509
|
+
failed.toLocaleString('en-US'),
|
|
510
|
+
'failed',
|
|
511
|
+
failed ? 'negative' : undefined,
|
|
512
|
+
),
|
|
513
|
+
),
|
|
514
|
+
h(Workers, { io, seen, now }),
|
|
515
|
+
h(Running, { io, up, now }),
|
|
516
|
+
],
|
|
517
|
+
waiting(got.owed, 'what is owed') ?? h(Handlers, { io, owed }),
|
|
518
|
+
)
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** The views this package draws. */
|
|
522
|
+
export let inspectViews: View[] = [
|
|
523
|
+
{ view: 'Effects.Page', match: true, asks, Render: EffectsPage },
|
|
524
|
+
]
|