Load limiting safeguards

This commit is contained in:
2026-05-06 04:04:53 +02:00
parent 47f6971c56
commit 2484ed2815
22 changed files with 374 additions and 144 deletions

View File

@@ -3,23 +3,25 @@ title: Overview
---
```js
import {API, POLL} from "./components/config.js";
import {API, POLL, POLL_HEAVY, apiFetch, pollDelay, sleep} from "./components/config.js";
```
```js
// Live polling — yields {data, ok, ts} every POLL ms
// Live polling — yields {data, ok, ts}; backs off when the API is slow/offline.
const summaryState = (async function*() {
let failures = 0;
while (true) {
let data, ok = false;
try {
const r = await fetch(`${API}/state/summary`);
const r = await apiFetch("/state/summary", {timeout: 20_000});
ok = r.ok;
data = ok ? await r.json() : {error: `HTTP ${r.status}`};
} catch (e) {
data = {error: "API unreachable"};
}
failures = ok ? 0 : failures + 1;
yield {data, ok, ts: new Date()};
await new Promise(res => setTimeout(res, POLL));
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
}
})();
```
@@ -49,17 +51,20 @@ refreshDecisions();
```js
// SBOM snapshots — repo coverage and total package count
const sbomSnapState = (async function*() {
let failures = 0;
while (true) {
let snapshots = [], totalPkgs = 0;
let snapshots = [], totalPkgs = 0, ok = false;
try {
const r = await fetch(`${API}/sbom/snapshots/`);
const r = await apiFetch("/sbom/snapshots/");
ok = r.ok;
if (r.ok) {
snapshots = await r.json();
totalPkgs = snapshots.reduce((s, sn) => s + (sn.entry_count ?? 0), 0);
}
} catch {}
failures = ok ? 0 : failures + 1;
yield {snapshots, totalPkgs};
await new Promise(res => setTimeout(res, POLL));
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
}
})();
```
@@ -67,17 +72,20 @@ const sbomSnapState = (async function*() {
```js
// Registered projects — milestone events tagged with registration
const regsState = (async function*() {
let failures = 0;
while (true) {
let rows = [];
let rows = [], ok = false;
try {
const r = await fetch(`${API}/progress/?event_type=milestone&limit=500`);
const r = await apiFetch("/progress/?event_type=milestone&limit=500");
ok = r.ok;
if (r.ok) {
const all = await r.json();
rows = all.filter(e => e.summary?.startsWith("Project registered with State Hub:"));
}
} catch {}
failures = ok ? 0 : failures + 1;
yield rows;
await new Promise(res => setTimeout(res, POLL));
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
}
})();
```
@@ -85,15 +93,16 @@ const regsState = (async function*() {
```js
// All-workstreams + all-tasks poll — drives the multi-mode chart
const wsChartState = (async function*() {
let failures = 0;
while (true) {
let wsAll = [], ok = false;
try {
const [rw, rt, rto, rr, rwi] = await Promise.all([
fetch(`${API}/workstreams/`),
fetch(`${API}/tasks/?limit=2000`),
fetch(`${API}/topics/`),
fetch(`${API}/repos/`),
fetch(`${API}/workstreams/workplan-index`),
apiFetch("/workstreams/"),
apiFetch("/tasks/?limit=2000"),
apiFetch("/topics/"),
apiFetch("/repos/"),
apiFetch("/workstreams/workplan-index"),
]);
ok = rw.ok && rt.ok && rto.ok && rr.ok;
if (ok) {
@@ -132,8 +141,9 @@ const wsChartState = (async function*() {
});
}
} catch {}
failures = ok ? 0 : failures + 1;
yield {wsAll, ok};
await new Promise(res => setTimeout(res, POLL));
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
}
})();
```