@jive-sh/workflow-platform 0.3.3 → 0.4.0
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/README.md +64 -21
- package/dist/dashboard/agent-usage.js +25 -0
- package/dist/dashboard/agent-usage.js.map +1 -0
- package/dist/dashboard/drilldown.js +16 -0
- package/dist/dashboard/drilldown.js.map +1 -0
- package/dist/dashboard/queue-lines.js +44 -0
- package/dist/dashboard/queue-lines.js.map +1 -0
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/keep-running.js +1 -1
- package/dist/keep-running.js.map +1 -1
- package/dist/pick-wakes.js +4 -4
- package/dist/pick-wakes.js.map +1 -1
- package/dist/queue-counts.js +7 -9
- package/dist/queue-counts.js.map +1 -1
- package/dist/steps.js +133 -30
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +115 -40
- package/dist/storage/sqlite-store.js.map +1 -1
- package/dist/storage/task-store.js +14 -1
- package/dist/storage/task-store.js.map +1 -1
- package/dist/tasks.js +215 -267
- package/dist/tasks.js.map +1 -1
- package/dist/views/runs-now.js +2 -1
- package/dist/views/runs-now.js.map +1 -1
- package/dist/views/workflows-view.js +74 -15
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/dashboard/agent-usage-line.tsx +28 -0
- package/src/dashboard/agent-usage.ts +48 -0
- package/src/dashboard/dashboard.css +57 -28
- package/src/dashboard/drilldown.ts +44 -0
- package/src/dashboard/index.tsx +1 -0
- package/src/dashboard/machine-controls.tsx +53 -0
- package/src/dashboard/queue-bar.tsx +43 -0
- package/src/dashboard/queue-chart.tsx +89 -76
- package/src/dashboard/queue-lines.ts +87 -0
- package/src/dashboard/workflow-drilldown.tsx +89 -0
- package/src/dashboard/workflows-dashboard.tsx +103 -37
- package/src/index.ts +11 -10
- package/src/keep-running.ts +3 -3
- package/src/pick-wakes.ts +14 -9
- package/src/queue-counts.ts +10 -14
- package/src/steps.ts +179 -42
- package/src/storage/sqlite-store.ts +123 -46
- package/src/storage/step-records.ts +14 -3
- package/src/storage/task-store.ts +88 -36
- package/src/tasks.ts +235 -301
- package/src/views/runs-now.ts +3 -2
- package/src/views/workflows-view.ts +102 -32
- package/dist/views/workflow-flows.js +0 -53
- package/dist/views/workflow-flows.js.map +0 -1
- package/src/dashboard/workflow-dag.tsx +0 -276
- package/src/views/workflow-flows.ts +0 -97
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* THE GENERIC VIEW OF A PROJECT'S WORKFLOWS
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* THE GENERIC VIEW OF A PROJECT'S WORKFLOWS, A WORKFLOW AT A TIME (`drilldown.ts`): the page enters at the project's top
|
|
5
|
+
* workflow and opens one sub-workflow step at a time, a breadcrumb saying where it is. A workflow's view shows its tasks as
|
|
6
|
+
* an addition (queued + in progress + blocked + done), its runs and limits, its tasks over time, its own steps with their
|
|
7
|
+
* kinds, and, read from its own records while it is open, why its blocked tasks are blocked, what its steps cost, its step
|
|
8
|
+
* graph and where its runs stopped. At the top it also shows what the project gives of its machine and its agents'
|
|
9
|
+
* account: the CPU limit, the stop of everything, and usage. It reads the platform's two readings
|
|
10
|
+
* (`views/workflows-view.ts`) and runs now (`views/runs-now.ts`). Uses React, which the host page brings.
|
|
10
11
|
*/
|
|
11
12
|
import { Fragment, useEffect, useState, type ReactNode } from 'react';
|
|
12
13
|
import type { PhaseRunsNow, StepRunsNow, WorkflowRunsNow } from '../views/runs-now';
|
|
13
14
|
import type { StepFunnel } from '../views/step-funnel';
|
|
14
15
|
import type { WorkflowGraph } from '../views/step-graph';
|
|
15
|
-
import type { SourceLink, StepCost, WorkflowFigures, WorkflowView, WorkflowsView } from '../views/workflows-view';
|
|
16
|
+
import type { SourceLink, StepCost, StepSummary, WorkflowFigures, WorkflowView, WorkflowsView } from '../views/workflows-view';
|
|
16
17
|
import { compact, duration, localTime, whenAgo } from '../views/format';
|
|
18
|
+
import { drillLevel } from './drilldown';
|
|
19
|
+
import { QueueBar } from './queue-bar';
|
|
17
20
|
import { QueueChart } from './queue-chart';
|
|
21
|
+
import { Breadcrumb, StepList } from './workflow-drilldown';
|
|
18
22
|
import { StepGraph } from './step-graph';
|
|
19
|
-
import {
|
|
23
|
+
import { AgentUsageLine } from './agent-usage-line';
|
|
24
|
+
import type { AgentUsage } from './agent-usage';
|
|
25
|
+
import { MachineControls } from './machine-controls';
|
|
20
26
|
|
|
21
27
|
/** What the page is given at each poll, all of it read at the request: every workflow, and where runs are now. */
|
|
22
28
|
export interface WorkflowsPageData {
|
|
23
29
|
readonly view: WorkflowsView;
|
|
24
30
|
readonly runsNow: ReadonlyArray<PhaseRunsNow>;
|
|
25
|
-
/**
|
|
26
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The one CPU limit and the newest reading of what the project used (`CpuLimit`); `threads`, how many the machine has,
|
|
33
|
+
* the most the limit can be set to.
|
|
34
|
+
*/
|
|
35
|
+
readonly cpu: { readonly limit: number; readonly threads?: number; readonly use: { readonly at: number; readonly cores: number; readonly held: number; readonly waiting: number } | null };
|
|
36
|
+
/** When everything was stopped by hand, unix seconds; none, or absent, while the project runs. */
|
|
37
|
+
readonly stopped?: { readonly at: number } | null;
|
|
38
|
+
/** What the agents' account has used of its limits (`agent-usage.ts`); absent where the project reads none. */
|
|
39
|
+
readonly usage?: AgentUsage;
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
type WorkflowLimits = NonNullable<WorkflowView['limits']>;
|
|
@@ -33,6 +46,11 @@ export type LimitName = 'runs' | 'agents';
|
|
|
33
46
|
|
|
34
47
|
/** Stores one of a workflow's limits: a whole number, or none for the run limit's default (its agents' limit). The project's own route. */
|
|
35
48
|
export type SetLimit = (r: { readonly workflow: string; readonly limit: LimitName; readonly value: number | null }) => Promise<void>;
|
|
49
|
+
/** What starts a workflow's runs, in words. */
|
|
50
|
+
const startsLine = (w: WorkflowView): string =>
|
|
51
|
+
w.startsOn.kind === 'queue' ? 'Runs on its queue.'
|
|
52
|
+
: w.startsOn.kind === 'inputs' ? `Runs when its inputs change: ${w.startsOn.says}.`
|
|
53
|
+
: 'Runs on a timer or a request.';
|
|
36
54
|
|
|
37
55
|
/** Where the project stands against its one CPU limit, in words. */
|
|
38
56
|
const cpuLine = (cpu: WorkflowsPageData['cpu'], now: number): string =>
|
|
@@ -46,18 +64,25 @@ export interface WorkflowsDashboardProps {
|
|
|
46
64
|
readonly error: string | null;
|
|
47
65
|
/** Where one workflow's figures are read from when it is opened (`WorkflowFigures`): the project's route for them. */
|
|
48
66
|
readonly figuresUrl: (workflow: string) => string;
|
|
49
|
-
/** Where a definition's link goes
|
|
50
|
-
readonly sourceHref
|
|
51
|
-
/** The project's own lines above everything: its title
|
|
67
|
+
/** Where a definition's link goes, where the project has somewhere to show its source; with none, no link shows. */
|
|
68
|
+
readonly sourceHref?: (source: SourceLink) => string;
|
|
69
|
+
/** The project's own lines above everything: its title. */
|
|
52
70
|
readonly header?: ReactNode;
|
|
53
|
-
/** The project's own panels, between the header and the workflows. */
|
|
54
|
-
readonly panels?: ReactNode;
|
|
55
71
|
/** The project's name for one phase, in its own words; the phase's key where it gives none. */
|
|
56
72
|
readonly phaseLabel?: (phase: string) => string;
|
|
57
|
-
/** The project's figures for one phase, on its heading line. */
|
|
58
|
-
readonly phaseSummary?: (phase: string) => ReactNode;
|
|
59
73
|
/** How the page sets a limit; with none the limits show without controls. */
|
|
60
74
|
readonly setLimit?: SetLimit;
|
|
75
|
+
/** Stores a new CPU limit; with none the limit shows without buttons (`machine-controls.tsx`). */
|
|
76
|
+
readonly setCpuLimit?: (limit: number) => Promise<void>;
|
|
77
|
+
/** Stops everything the project runs, and resumes it; with neither, no button shows. */
|
|
78
|
+
readonly stopEverything?: () => Promise<void>;
|
|
79
|
+
readonly resume?: () => Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* THE DRILL-DOWN (`drilldown.ts`): the sub-workflow steps opened below the top workflow, top first, and each level's
|
|
82
|
+
* address, which the host page routes back here as `path`.
|
|
83
|
+
*/
|
|
84
|
+
readonly path: ReadonlyArray<string>;
|
|
85
|
+
readonly hrefOf: (path: ReadonlyArray<string>) => string;
|
|
61
86
|
}
|
|
62
87
|
|
|
63
88
|
/** Polls a JSON route one request at a time, the next asked for when this one has answered. */
|
|
@@ -268,11 +293,21 @@ function WorkflowDetail({ workflow, runs, now, figuresUrl }: { readonly workflow
|
|
|
268
293
|
{figures === null ? <p className={read.error === null ? 'wp-line wp-mut' : 'wp-line wp-bad'}>{read.error === null ? 'Reading its figures…' : `Its figures could not be read: ${read.error}`}</p> : (
|
|
269
294
|
<>
|
|
270
295
|
<p className="wp-line wp-mut">Its figures over the last {figures.hours} h, read {whenAgo(figures.at, now)}.</p>
|
|
296
|
+
{figures.blocked.length === 0 ? null : (
|
|
297
|
+
<>
|
|
298
|
+
<h4 className="wp-h4">Blocked, by reason</h4>
|
|
299
|
+
<table className="wp-reasons">
|
|
300
|
+
<tbody>
|
|
301
|
+
{figures.blocked.map((b) => <tr key={b.why}><td className="wp-r">{b.tasks.toLocaleString("en-US")}</td><td>{b.why}</td></tr>)}
|
|
302
|
+
</tbody>
|
|
303
|
+
</table>
|
|
304
|
+
</>
|
|
305
|
+
)}
|
|
271
306
|
{workflow.item === null ? null : <p className="wp-line">{yieldLine(figures, workflow.finishedWord)}</p>}
|
|
272
307
|
<p className="wp-line">{runCostLine(figures)}</p>
|
|
273
308
|
<StepsTable workflow={figures} usesAgents={workflow.usesAgents} runs={runs} now={now} />
|
|
274
309
|
<h4 className="wp-h4">Step graph</h4>
|
|
275
|
-
<StepGraph graph={figures.graph}
|
|
310
|
+
<div className="wp-tablewrap"><StepGraph graph={figures.graph} /></div>
|
|
276
311
|
<h4 className="wp-h4">Where runs stopped</h4>
|
|
277
312
|
<FunnelTable funnel={figures.funnel} />
|
|
278
313
|
</>
|
|
@@ -281,8 +316,47 @@ function WorkflowDetail({ workflow, runs, now, figuresUrl }: { readonly workflow
|
|
|
281
316
|
);
|
|
282
317
|
}
|
|
283
318
|
|
|
284
|
-
|
|
319
|
+
/**
|
|
320
|
+
* ONE LEVEL OF THE DRILL-DOWN: the breadcrumb, then the workflow opened: what it is, its tasks as an addition, its runs and
|
|
321
|
+
* limits, and its own steps, each with its kind, a sub-workflow step a link one level down. Below the top, its figures too.
|
|
322
|
+
*/
|
|
323
|
+
function DrillLevelView({ data, path, hrefOf, now, figuresUrl, sourceHref, phaseLabel, setLimit }: {
|
|
324
|
+
readonly data: WorkflowsPageData; readonly path: ReadonlyArray<string>; readonly hrefOf: (path: ReadonlyArray<string>) => string; readonly now: number;
|
|
325
|
+
readonly figuresUrl: (workflow: string) => string; readonly sourceHref: ((source: SourceLink) => string) | undefined; readonly phaseLabel: (phase: string) => string; readonly setLimit: SetLimit | undefined;
|
|
326
|
+
}) {
|
|
327
|
+
const level = drillLevel(data.view, path);
|
|
328
|
+
const all = data.view.groups.flatMap((g) => g.workflows);
|
|
329
|
+
const workflowOf = (name: string) => all.find((w) => w.name === name);
|
|
330
|
+
const runsOf = (name: string) => data.runsNow.flatMap((p) => p.workflows).find((r) => r.workflow === name);
|
|
331
|
+
const w = level.workflow;
|
|
332
|
+
const runs = w === null ? undefined : runsOf(w.name);
|
|
333
|
+
// At the top, each step is a workflow of one of the project's stages, which heads its steps.
|
|
334
|
+
const stageOf = (workflow: string | null) => (workflow === null ? null : workflowOf(workflow)?.phase ?? null);
|
|
335
|
+
return (
|
|
336
|
+
<section className="wp-drill">
|
|
337
|
+
{/* The breadcrumb is the title: its last part names the workflow opened. */}
|
|
338
|
+
<Breadcrumb crumbs={level.crumbs} hrefOf={hrefOf} after={w === null || sourceHref === undefined ? null : <a className="wp-mut wp-drill-source" href={sourceHref(w.source)}>source</a>} />
|
|
339
|
+
{level.notFound === null ? null : <p className="wp-line wp-bad">{level.name} has no sub-workflow step named {level.notFound}.</p>}
|
|
340
|
+
<p className="wp-line">{level.description}</p>
|
|
341
|
+
{w === null ? null : <p className="wp-line wp-mut">{startsLine(w)}</p>}
|
|
342
|
+
{w === null || w.queue === null ? null : <QueueBar queue={w.queue} />}
|
|
343
|
+
{w === null ? null : <div className="wp-node-status wp-drill-status"><WorkflowStatus workflow={w} runs={runs} limits={w.limits} setLimit={setLimit} /></div>}
|
|
344
|
+
{/* Its tasks over time: at the top a row for each step that has tasks; below it, the workflow opened and each such step of its own. */}
|
|
345
|
+
<QueueChart view={data.view} level={path.join("/")} rowWord={w === null ? "step" : "workflow"}
|
|
346
|
+
workflows={[...(w === null ? [] : [w]), ...level.steps.flatMap((s) => { const sub = s.workflow === null ? undefined : workflowOf(s.workflow); return sub === undefined || sub.name === w?.name ? [] : [sub]; })]} />
|
|
347
|
+
<h3 className="wp-h3">Steps</h3>
|
|
348
|
+
<StepList
|
|
349
|
+
steps={level.steps} path={level.crumbs[level.crumbs.length - 1]!.path} hrefOf={hrefOf} workflowOf={workflowOf} runsOf={runsOf} runs={runs}
|
|
350
|
+
{...(w === null ? { groupKey: (s: StepSummary) => stageOf(s.workflow), groupOf: (s: StepSummary) => { const stage = stageOf(s.workflow); return stage === null ? null : phaseLabel(stage); } } : {})}
|
|
351
|
+
/>
|
|
352
|
+
{w === null ? null : <WorkflowDetail workflow={w} runs={runs} now={now} figuresUrl={figuresUrl} />}
|
|
353
|
+
</section>
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function WorkflowsDashboard({ data, error, figuresUrl, sourceHref, header, phaseLabel, setLimit, setCpuLimit, stopEverything, resume, path, hrefOf }: WorkflowsDashboardProps) {
|
|
285
358
|
const now = Date.now() / 1000;
|
|
359
|
+
const atTheTop = path.length === 0;
|
|
286
360
|
return (
|
|
287
361
|
<div className="wp-page">
|
|
288
362
|
{header}
|
|
@@ -290,24 +364,16 @@ export function WorkflowsDashboard({ data, error, figuresUrl, sourceHref, header
|
|
|
290
364
|
{error !== null ? `The workflows could not be read: ${error}` : data === null ? 'Reading the workflows…' : `Read from the records ${whenAgo(data.view.at, now)}.`}
|
|
291
365
|
</p>
|
|
292
366
|
{data === null ? null : <p className={data.cpu.use !== null && data.cpu.use.cores > data.cpu.limit ? 'wp-line wp-bad' : 'wp-line'}>{cpuLine(data.cpu, now)}</p>}
|
|
293
|
-
{
|
|
294
|
-
{data === null ? null :
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return <>{p === undefined ? 0 : p.runs} running, {p === undefined ? 0 : p.onAgents} on agents{phaseSummary === undefined ? null : <> · {phaseSummary(phase)}</>}</>;
|
|
304
|
-
}}
|
|
305
|
-
nodeStatus={(w) => <WorkflowStatus workflow={w} runs={runsOf(w)} limits={w.limits} setLimit={setLimit} />}
|
|
306
|
-
nodeHref={(w) => sourceHref(w.source)}
|
|
307
|
-
detail={(w) => <WorkflowDetail workflow={w} runs={runsOf(w)} now={now} figuresUrl={figuresUrl} />}
|
|
308
|
-
/>
|
|
309
|
-
);
|
|
310
|
-
})()}
|
|
367
|
+
{/* Nothing a level decides is drawn before the first read: a server draws one page for every level's address. */}
|
|
368
|
+
{data === null || !atTheTop ? null : (
|
|
369
|
+
<>
|
|
370
|
+
<MachineControls cpu={data.cpu} stopped={data.stopped ?? null} now={now} {...(setCpuLimit === undefined ? {} : { setCpuLimit })} {...(stopEverything === undefined ? {} : { stopEverything })} {...(resume === undefined ? {} : { resume })} />
|
|
371
|
+
{data.usage === undefined ? null : <AgentUsageLine usage={data.usage} now={now} />}
|
|
372
|
+
</>
|
|
373
|
+
)}
|
|
374
|
+
{data === null ? null : (
|
|
375
|
+
<DrillLevelView data={data} path={path} hrefOf={hrefOf} now={now} figuresUrl={figuresUrl} sourceHref={sourceHref} phaseLabel={(phase) => (phaseLabel === undefined ? phase : phaseLabel(phase))} setLimit={setLimit} />
|
|
376
|
+
)}
|
|
311
377
|
</div>
|
|
312
378
|
);
|
|
313
379
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { makePickWakes } from './pick-wakes';
|
|
|
14
14
|
import { makeStepFiles } from './step-files';
|
|
15
15
|
import { makeStepUsage } from './step-usage';
|
|
16
16
|
import { keptRunningByItsBudget, makeSteps, runLimitOf } from './steps';
|
|
17
|
-
import {
|
|
17
|
+
import { blockedReasons, makeTasks } from './tasks';
|
|
18
18
|
import { buildWorkflowFigures, buildWorkflowsView, type WorkflowFigures, type WorkflowsView, type WorkflowView } from './views/workflows-view';
|
|
19
19
|
import { makeQueueCounts } from './queue-counts';
|
|
20
20
|
import { sqliteBudgets, type LimitStore } from './storage/budgets';
|
|
@@ -50,8 +50,8 @@ export * from './views/runs-now';
|
|
|
50
50
|
export * from './views/step-funnel';
|
|
51
51
|
export * from './views/step-graph';
|
|
52
52
|
export * from './views/workflows-view';
|
|
53
|
-
export * from './views/workflow-flows';
|
|
54
53
|
export type { NewNote, TaskStore, TextChange } from './storage/task-store';
|
|
54
|
+
export type { AgentUsage, UsageLimit } from './dashboard/agent-usage';
|
|
55
55
|
|
|
56
56
|
/** Where a project's records live: each store an interface, so another database can stand behind any of them. */
|
|
57
57
|
export interface WorkflowStorage {
|
|
@@ -89,25 +89,23 @@ export const sqliteStorage = (options: {
|
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* ONE PROJECT'S PLATFORM. `Phase` is where the project shows a workflow; `R` what its workflows' lists of work run under.
|
|
92
|
-
* `rules` adds the project's own queue rules (`TaskRules`).
|
|
93
92
|
*/
|
|
94
93
|
export const createWorkflowPlatform = <Phase extends string, R>(input: {
|
|
95
94
|
readonly project: WorkflowProject;
|
|
96
95
|
readonly storage: WorkflowStorage;
|
|
97
|
-
readonly rules: TaskRules;
|
|
98
96
|
}) => {
|
|
99
97
|
const { project, storage } = input;
|
|
100
98
|
const wakes = makePickWakes();
|
|
101
99
|
const stepFiles = makeStepFiles({ tree: project.tree, runLightNow: project.runLightNow });
|
|
102
100
|
const stepUsage = makeStepUsage({ variable: project.stepRecordVariable, addStepCompile: (record) => { Effect.runFork(Effect.catchTag(storage.stepRecords.addStepCompile(record), 'StorageError', (e) => Effect.logError(`[step-runs] a compile of step record ${record}: ${e.reason}`))); } });
|
|
103
|
-
const tasks = makeTasks({ store: storage.tasks, engine: storage.engine, stepRecords: storage.stepRecords, wakes, texts: project.texts
|
|
101
|
+
const tasks = makeTasks({ store: storage.tasks, engine: storage.engine, stepRecords: storage.stepRecords, wakes, texts: project.texts });
|
|
104
102
|
const steps = makeSteps<Phase, R>({
|
|
105
103
|
sourceRoot: project.sourceRoot, stepRecords: storage.stepRecords, engine: storage.engine, tasks, wakes, budgets: storage.budgets, stepFiles,
|
|
106
104
|
CurrentStepUsage: stepUsage.CurrentStepUsage, isTransientFailure: project.isTransientFailure, thisProcess: project.processes.thisProcess, inputs: storage.inputs,
|
|
107
105
|
queueChanged: (workflow) => queueCounts.changed(workflow),
|
|
108
106
|
});
|
|
109
|
-
const queueCounts = makeQueueCounts
|
|
110
|
-
store: storage.tasks, tasks, wakes,
|
|
107
|
+
const queueCounts = makeQueueCounts({
|
|
108
|
+
store: storage.tasks, tasks, wakes,
|
|
111
109
|
withQueues: () => steps.declaredWorkflows().filter((d) => d.item !== null).map((d) => d.name),
|
|
112
110
|
});
|
|
113
111
|
/**
|
|
@@ -140,15 +138,18 @@ export const createWorkflowPlatform = <Phase extends string, R>(input: {
|
|
|
140
138
|
* Every workflow as a dashboard shows it before one is opened, read now (`views/workflows-view.ts` `buildWorkflowsView`).
|
|
141
139
|
* `phases` is the order the project's page shows them in.
|
|
142
140
|
*/
|
|
143
|
-
const view = (r: { readonly now: number; readonly phases: ReadonlyArray<string
|
|
141
|
+
const view = (r: { readonly now: number; readonly phases: ReadonlyArray<string>; readonly top: { readonly name: string; readonly description: string } }): Effect.Effect<WorkflowsView, StorageError> => Effect.gen(function* () {
|
|
144
142
|
const limits = yield* limitsNow();
|
|
145
|
-
return yield* buildWorkflowsView({ declared: steps.declaredWorkflows(), phases: r.phases, now: r.now, taskStore: storage.tasks, locate, limitsOf: (name) => limits[name] ?? null });
|
|
143
|
+
return yield* buildWorkflowsView({ declared: steps.declaredWorkflows(), phases: r.phases, top: r.top, now: r.now, taskStore: storage.tasks, locate, limitsOf: (name) => limits[name] ?? null });
|
|
146
144
|
});
|
|
147
145
|
|
|
148
146
|
/** One workflow's figures over the `hours` before `now`, read from its own records (`buildWorkflowFigures`); none for one not declared. */
|
|
149
147
|
const figures = (r: { readonly workflow: string; readonly now: number; readonly hours: number }): Effect.Effect<WorkflowFigures | null, StorageError> => {
|
|
150
148
|
const declaration = steps.declaredWorkflows().find((d) => d.name === r.workflow);
|
|
151
|
-
return declaration === undefined ? Effect.succeed(null) : buildWorkflowFigures({
|
|
149
|
+
return declaration === undefined ? Effect.succeed(null) : buildWorkflowFigures({
|
|
150
|
+
declaration, now: r.now, hours: r.hours, records: storage.stepRecords, engine: storage.engine, locate,
|
|
151
|
+
blocked: declaration.item === null ? Effect.succeed([]) : Effect.map(tasks.taskSummaries({ workflow: r.workflow }), blockedReasons),
|
|
152
|
+
});
|
|
152
153
|
};
|
|
153
154
|
return { project, storage, wakes, stepFiles, stepUsage, tasks, steps, view, figures, limitsNow, queueCounts };
|
|
154
155
|
};
|
package/src/keep-running.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* one trigger, with no code of its own: each turn it starts as many runs as the workflow's run limit keeps (`runLimit`) above
|
|
8
8
|
* the runs going, as soon as a run ends and otherwise on a fallback timer. There is no sharing between workflows, no order,
|
|
9
9
|
* no cap per item and no check of usage: a run with nothing to pick waits for an item (`steps.ts` `untilPicked`), and the
|
|
10
|
-
*
|
|
10
|
+
* blocking a Pick runs and the queue's order keep a run off what it cannot finish. A run limit of 0 holds one workflow.
|
|
11
11
|
*/
|
|
12
12
|
import { keptRunningByItsBudget, type WorkflowDeclaration } from './steps';
|
|
13
13
|
import { runLimit, type WorkflowLimits } from './storage/budgets';
|
|
@@ -20,7 +20,7 @@ export const TURN_LIMIT_MS = 50_000;
|
|
|
20
20
|
export const START_LIMIT_SECONDS = 20;
|
|
21
21
|
|
|
22
22
|
/** The workflows this trigger keeps running, each with a budget. Pure. */
|
|
23
|
-
export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'steps'>>(declared: ReadonlyArray<D>): ReadonlyArray<D> =>
|
|
23
|
+
export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items' | 'steps'>>(declared: ReadonlyArray<D>): ReadonlyArray<D> =>
|
|
24
24
|
declared.filter(keptRunningByItsBudget);
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -30,7 +30,7 @@ export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unk
|
|
|
30
30
|
export const runsToStart = (w: { readonly kept: number; readonly running: number }): number => Math.max(w.kept - w.running, 0);
|
|
31
31
|
|
|
32
32
|
/** One turn's plan: for each budgeted workflow, the runs going and how many to start. Pure but for the reads it is given. */
|
|
33
|
-
export const planRunStarts = <D extends Pick<WorkflowDeclaration<string, unknown>, 'name' | 'pending' | 'steps'>>(input: {
|
|
33
|
+
export const planRunStarts = <D extends Pick<WorkflowDeclaration<string, unknown>, 'name' | 'pending' | 'items' | 'steps'>>(input: {
|
|
34
34
|
readonly declared: ReadonlyArray<D>;
|
|
35
35
|
readonly limitsOf: (workflow: string) => WorkflowLimits;
|
|
36
36
|
readonly runningRuns: (workflow: string) => number;
|
package/src/pick-wakes.ts
CHANGED
|
@@ -45,8 +45,11 @@ export interface PickWakes {
|
|
|
45
45
|
readonly onRunPlanChanged: (listener: (workflow: string | null) => void) => void;
|
|
46
46
|
/** Calls `listener` on each wake that reaches this process, raised here or relayed: what else follows a queue's changes (`queue-counts.ts`). */
|
|
47
47
|
readonly onWake: (listener: (wake: Wake) => void) => void;
|
|
48
|
-
/**
|
|
49
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Waits until a wake reaches this workflow after `after` wakes, at once when one already has: `woken`. `released`
|
|
50
|
+
* where its process is handing its runs to another (`releaseWaiting`), which a step answers by standing down.
|
|
51
|
+
*/
|
|
52
|
+
readonly untilPickWoken: (r: { readonly workflow: string; readonly after: number }) => Effect.Effect<'woken' | 'released'>;
|
|
50
53
|
/** A waiting Pick picked again after a wake: `ms` is how long that pick took. */
|
|
51
54
|
readonly countRePick: (workflow: string, ms: number) => void;
|
|
52
55
|
/**
|
|
@@ -57,8 +60,10 @@ export interface PickWakes {
|
|
|
57
60
|
/** Applies a wake another process relayed, without relaying it again. */
|
|
58
61
|
readonly wake: (wake: Wake) => void;
|
|
59
62
|
/**
|
|
60
|
-
* LETS EVERY WAITING
|
|
61
|
-
* so its run
|
|
63
|
+
* LETS EVERY WAITING STEP GO, now and from now on, for a process handing its runs to another: each wait ends `released`,
|
|
64
|
+
* and its step stands down (`steps.ts` `HANDED_OVER`), so its run ends untried and the next process starts one. Ended
|
|
65
|
+
* interrupted, the engine tried the step again 10 times and then failed its run: a run waiting for an agent was recorded
|
|
66
|
+
* as a failed try of its task (2026-11-19). A waiting step has done no work, and kept
|
|
62
67
|
* waiting it held its process's handover open for the engine's full limit, 10 minutes (2026-11-11).
|
|
63
68
|
*/
|
|
64
69
|
readonly releaseWaiting: () => void;
|
|
@@ -147,18 +152,18 @@ export const makePickWakes = (): PickWakes => {
|
|
|
147
152
|
for (const waiter of [...waiters]) waiter.release();
|
|
148
153
|
},
|
|
149
154
|
untilPickWoken: (input) =>
|
|
150
|
-
Effect.callback<
|
|
151
|
-
if (released) return resume(Effect.
|
|
152
|
-
if (pickWakesSoFar(input.workflow) !== input.after) return resume(Effect.
|
|
155
|
+
Effect.callback<'woken' | 'released'>((resume) => {
|
|
156
|
+
if (released) return resume(Effect.succeed('released'));
|
|
157
|
+
if (pickWakesSoFar(input.workflow) !== input.after) return resume(Effect.succeed('woken'));
|
|
153
158
|
const waiter: Waiter = {
|
|
154
159
|
workflow: input.workflow,
|
|
155
160
|
wake: () => {
|
|
156
161
|
waiters.delete(waiter);
|
|
157
|
-
resume(Effect.
|
|
162
|
+
resume(Effect.succeed('woken'));
|
|
158
163
|
},
|
|
159
164
|
release: () => {
|
|
160
165
|
waiters.delete(waiter);
|
|
161
|
-
resume(Effect.
|
|
166
|
+
resume(Effect.succeed('released'));
|
|
162
167
|
},
|
|
163
168
|
};
|
|
164
169
|
waiters.add(waiter);
|
package/src/queue-counts.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* EACH QUEUE'S COUNTS, RECORDED WHEN ITS QUEUE MAY HAVE CHANGED (`queue_counts`), so a page reads the newest row and
|
|
3
|
-
* counts. A workflow's tasks by
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* one that has read each task's inputs as its Pick reads them, so the page and the Pick put a task in the same bucket.
|
|
2
|
+
* EACH QUEUE'S COUNTS, RECORDED WHEN ITS QUEUE MAY HAVE CHANGED (`queue_counts`), so a page reads the newest row and its
|
|
3
|
+
* history and never counts. A workflow's tasks by status are read from its tasks' notes (`tasks.ts` `taskSummaries`), once
|
|
4
|
+
* per change, in the one process that runs the project's workflows. A count only counts: blocking a task is its Pick's
|
|
5
|
+
* step, never a page's or this (`tasks.ts` `settleQueue`).
|
|
7
6
|
*
|
|
8
7
|
* WHAT COUNTS AS A CHANGE: every wake of a workflow's Picks (`pick-wakes.ts`: a note on one of its tasks, an item new to
|
|
9
8
|
* its list, one of its runs ending, a limit set), and a Pick claiming an item (`changed`). Every change within
|
|
@@ -14,26 +13,23 @@ import { Effect } from 'effect';
|
|
|
14
13
|
import type { PickWakes } from './pick-wakes';
|
|
15
14
|
import type { StorageError } from './storage/storage-error';
|
|
16
15
|
import type { TaskStore } from './storage/task-store';
|
|
17
|
-
import {
|
|
16
|
+
import { statusCounts, type Tasks } from './tasks';
|
|
18
17
|
|
|
19
18
|
/** How long after a queue's first change it is counted: every change in that time is in the one count. */
|
|
20
19
|
export const COUNT_AFTER_MS = 5_000;
|
|
21
20
|
|
|
22
|
-
export const makeQueueCounts =
|
|
21
|
+
export const makeQueueCounts = (deps: {
|
|
23
22
|
readonly store: Pick<TaskStore, 'recordQueueCounts'>;
|
|
24
23
|
readonly tasks: Pick<Tasks, 'taskSummaries'>;
|
|
25
24
|
readonly wakes: Pick<PickWakes, 'onWake'>;
|
|
26
25
|
/** The workflows that have a queue, now. */
|
|
27
26
|
readonly withQueues: () => ReadonlyArray<string>;
|
|
28
|
-
/** Reads a workflow's tasks' inputs where it declares them (`steps.ts` `readTaskInputs`), as its Pick does before it reads its queue. */
|
|
29
|
-
readonly readTaskInputs: (workflow: string) => Effect.Effect<unknown, unknown, R>;
|
|
30
27
|
/** `COUNT_AFTER_MS` where absent; a test names a shorter one. */
|
|
31
28
|
readonly countAfterMs?: number;
|
|
32
29
|
}) => {
|
|
33
|
-
/** Counts one workflow's queue now and records it.
|
|
34
|
-
const count = (workflow: string): Effect.Effect<void, StorageError
|
|
35
|
-
yield*
|
|
36
|
-
const counts = bucketCounts(yield* deps.tasks.taskSummaries({ workflow }));
|
|
30
|
+
/** Counts one workflow's queue now and records it. */
|
|
31
|
+
const count = (workflow: string): Effect.Effect<void, StorageError> => Effect.gen(function* () {
|
|
32
|
+
const counts = statusCounts(yield* deps.tasks.taskSummaries({ workflow }));
|
|
37
33
|
yield* deps.store.recordQueueCounts({ at: Date.now() / 1000, counts: Object.entries(counts).map(([bucket, tasks]) => ({ workflow, bucket, tasks })) });
|
|
38
34
|
});
|
|
39
35
|
|
|
@@ -43,7 +39,7 @@ export const makeQueueCounts = <R>(deps: {
|
|
|
43
39
|
* Starts recording: for the one process that runs the project's workflows, which gives `run`, how it runs an effect of
|
|
44
40
|
* theirs. Every queue is counted once at the start, then each on its changes.
|
|
45
41
|
*/
|
|
46
|
-
const record = (run: (count: Effect.Effect<void, StorageError
|
|
42
|
+
const record = (run: (count: Effect.Effect<void, StorageError>) => Promise<void>): void => {
|
|
47
43
|
const due = new Set<string>();
|
|
48
44
|
countSoon = (workflow) => {
|
|
49
45
|
if (due.has(workflow) || !deps.withQueues().includes(workflow)) return;
|