generated from coulomb/repo-seed
Load limiting safeguards
This commit is contained in:
@@ -3,7 +3,7 @@ title: Token Cost
|
||||
---
|
||||
|
||||
```js
|
||||
import {API} from "./components/config.js";
|
||||
import {apiFetch, pollDelay, sleep} from "./components/config.js";
|
||||
import {refCell} from "./components/ref-cell.js";
|
||||
const POLL = 60_000;
|
||||
```
|
||||
@@ -11,14 +11,15 @@ const POLL = 60_000;
|
||||
```js
|
||||
// Fetch token events, by-repo summary, workstreams, and tasks in parallel
|
||||
const tokenState = (async function*() {
|
||||
let failures = 0;
|
||||
while (true) {
|
||||
let byRepo = [], events = [], wsMap = {}, taskMap = {}, ok = false;
|
||||
try {
|
||||
const [r1, r2, r3, r4] = await Promise.all([
|
||||
fetch(`${API}/token-events/by-repo/`),
|
||||
fetch(`${API}/token-events/?limit=1000`),
|
||||
fetch(`${API}/workstreams/`),
|
||||
fetch(`${API}/tasks/`),
|
||||
apiFetch("/token-events/by-repo/"),
|
||||
apiFetch("/token-events/?limit=1000"),
|
||||
apiFetch("/workstreams/"),
|
||||
apiFetch("/tasks/"),
|
||||
]);
|
||||
ok = r1.ok && r2.ok;
|
||||
if (ok) {
|
||||
@@ -34,8 +35,9 @@ const tokenState = (async function*() {
|
||||
for (const t of taskList) taskMap[t.id] = t;
|
||||
}
|
||||
} catch {}
|
||||
failures = ok ? 0 : failures + 1;
|
||||
yield {byRepo, events, wsMap, taskMap, 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