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,7 +3,7 @@ title: Token Cost
---
```js
import {API} from "./components/config.js";
import {apiFetch, pollDelay, sleep} from "./components/config.js";
import {refCell} from "./components/ref-cell.js";
const POLL = 60_000;
```
@@ -11,14 +11,15 @@ const POLL = 60_000;
```js
// Fetch token events, by-repo summary, workstreams, and tasks in parallel
const tokenState = (async function*() {
let failures = 0;
while (true) {
let byRepo = [], events = [], wsMap = {}, taskMap = {}, ok = false;
try {
const [r1, r2, r3, r4] = await Promise.all([
fetch(`${API}/token-events/by-repo/`),
fetch(`${API}/token-events/?limit=1000`),
fetch(`${API}/workstreams/`),
fetch(`${API}/tasks/`),
apiFetch("/token-events/by-repo/"),
apiFetch("/token-events/?limit=1000"),
apiFetch("/workstreams/"),
apiFetch("/tasks/"),
]);
ok = r1.ok && r2.ok;
if (ok) {
@@ -34,8 +35,9 @@ const tokenState = (async function*() {
for (const t of taskList) taskMap[t.id] = t;
}
} catch {}
failures = ok ? 0 : failures + 1;
yield {byRepo, events, wsMap, taskMap, ok, ts: new Date()};
await new Promise(res => setTimeout(res, POLL));
await sleep(pollDelay({ok, base: POLL, failures}));
}
})();
```