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,18 +3,19 @@ title: Decisions
---
```js
import {API, POLL} from "./components/config.js";
import {API, POLL_HEAVY, apiFetch, pollDelay, sleep} from "./components/config.js";
```
```js
// Fetch decisions + topics (for domain context) in parallel
const decState = (async function*() {
let failures = 0;
while (true) {
let data = [], ok = false;
try {
const [rd, rt] = await Promise.all([
fetch(`${API}/decisions/?limit=500`),
fetch(`${API}/topics/`),
apiFetch("/decisions/?limit=500"),
apiFetch("/topics/"),
]);
ok = rd.ok && rt.ok;
if (ok) {
@@ -43,8 +44,9 @@ const decState = (async function*() {
});
}
} catch {}
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}));
}
})();
```