generated from coulomb/repo-seed
Load limiting safeguards
This commit is contained in:
@@ -3,20 +3,21 @@ title: Goals
|
||||
---
|
||||
|
||||
```js
|
||||
import {API} from "./components/config.js";
|
||||
import {API, apiFetch, pollDelay, sleep} from "./components/config.js";
|
||||
const POLL = 20_000;
|
||||
```
|
||||
|
||||
```js
|
||||
const goalsState = (async function*() {
|
||||
let failures = 0;
|
||||
while (true) {
|
||||
let domains = [], domainGoals = [], repoGoals = [], repos = [], ok = false;
|
||||
try {
|
||||
const [rd, rdg, rrg, rr] = await Promise.all([
|
||||
fetch(`${API}/domains/?status=active`),
|
||||
fetch(`${API}/domain-goals/`),
|
||||
fetch(`${API}/repo-goals/`),
|
||||
fetch(`${API}/repos/`),
|
||||
apiFetch("/domains/?status=active"),
|
||||
apiFetch("/domain-goals/"),
|
||||
apiFetch("/repo-goals/"),
|
||||
apiFetch("/repos/"),
|
||||
]);
|
||||
ok = rd.ok && rdg.ok && rrg.ok && rr.ok;
|
||||
if (ok) {
|
||||
@@ -25,8 +26,9 @@ const goalsState = (async function*() {
|
||||
]);
|
||||
}
|
||||
} catch {}
|
||||
failures = ok ? 0 : failures + 1;
|
||||
yield {domains, domainGoals, repoGoals, repos, ok, ts: new Date()};
|
||||
await new Promise(res => setTimeout(res, POLL));
|
||||
await sleep(pollDelay({ok, base: POLL, failures}));
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user