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,24 +3,26 @@ title: Progress
---
```js
import {API, POLL} from "./components/config.js";
import {POLL_HEAVY, apiFetch, pollDelay, sleep} from "./components/config.js";
```
```js
const progState = (async function*() {
let failures = 0;
while (true) {
let data = [], tokenEvents = [], ok = false;
try {
const [r1, r2] = await Promise.all([
fetch(`${API}/progress/?limit=500`),
fetch(`${API}/token-events/?limit=1000`),
apiFetch("/progress/?limit=500"),
apiFetch("/token-events/?limit=1000"),
]);
ok = r1.ok;
data = ok ? await r1.json() : [];
tokenEvents = r2.ok ? await r2.json() : [];
} catch {}
failures = ok ? 0 : failures + 1;
yield {data, tokenEvents, ok, ts: new Date()};
await new Promise(res => setTimeout(res, POLL));
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
}
})();
```