Load limiting safeguards
This commit is contained in:
parent
47f6971c56
commit
2484ed2815
22 changed files with 374 additions and 144 deletions
|
|
@ -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}));
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue