Load limiting safeguards
This commit is contained in:
parent
47f6971c56
commit
2484ed2815
22 changed files with 374 additions and 144 deletions
|
|
@ -3,25 +3,27 @@ title: Domains
|
|||
---
|
||||
|
||||
```js
|
||||
import {API, POLL} from "./components/config.js";
|
||||
import {API, POLL_HEAVY, apiFetch, pollDelay, sleep} from "./components/config.js";
|
||||
```
|
||||
|
||||
```js
|
||||
const domainsState = (async function*() {
|
||||
let failures = 0;
|
||||
while (true) {
|
||||
let domains = [], repos = [], ok = false;
|
||||
try {
|
||||
const [rd, rr] = await Promise.all([
|
||||
fetch(`${API}/domains/?status=all`),
|
||||
fetch(`${API}/repos/`),
|
||||
apiFetch("/domains/?status=all"),
|
||||
apiFetch("/repos/"),
|
||||
]);
|
||||
ok = rd.ok && rr.ok;
|
||||
if (ok) {
|
||||
[domains, repos] = await Promise.all([rd.json(), rr.json()]);
|
||||
}
|
||||
} catch {}
|
||||
failures = ok ? 0 : failures + 1;
|
||||
yield {domains, repos, 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