Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ export async function checkBuilds(env: Env, at = new Date()): Promise<{ failed:
try {
scripts = (await cf(env, `/accounts/${account}/workers/scripts`)).result || [];
if (!scripts.length) return { failed: 0 };
const q = new URLSearchParams({ external_script_ids: scripts.map((s) => s.tag).join(",") });
const r = (await cf(env, `/accounts/${account}/builds/builds/latest?${q}`)).result || {};
latest = r.builds || r;
// The endpoint takes at most 20 script ids per request.
latest = {};
for (let i = 0; i < scripts.length; i += 20) {
const q = new URLSearchParams({ external_script_ids: scripts.slice(i, i + 20).map((s) => s.tag).join(",") });
const r = (await cf(env, `/accounts/${account}/builds/builds/latest?${q}`)).result || {};
Object.assign(latest, r.builds || r);
}
} catch (e) {
if (!/answered 403/.test(String((e as Error)?.message))) throw e;
// The token lacks Workers Scripts Read or Workers CI Read: say so once instead of failing every run.
Expand Down
7 changes: 5 additions & 2 deletions test/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ before(async () => {
return Response.json({ success: true, errors: [], result, result_info: {} });
}
if (u.pathname === "/client/v4/accounts/acc/workers/scripts") {
return Response.json({ success: true, errors: [], result: [{ id: "app", tag: "t-app" }, { id: "other", tag: "t-other" }] });
const filler = Array.from({ length: 20 }, (_, i) => ({ id: `w${i}`, tag: `t-w${i}` }));
return Response.json({ success: true, errors: [], result: [...filler, { id: "app", tag: "t-app" }, { id: "other", tag: "t-other" }] });
}
if (u.pathname === "/client/v4/accounts/acc/builds/builds/latest") {
assert.equal(u.searchParams.get("external_script_ids"), "t-app,t-other");
const ids = u.searchParams.get("external_script_ids").split(",");
assert.ok(ids.length <= 20, "at most 20 script ids per request");
if (!ids.includes("t-app")) return Response.json({ success: true, errors: [], result: { builds: {} } });
const uuid = buildOutcome === "fail" ? "b-fail" : "b-ok";
return Response.json({ success: true, errors: [], result: { builds: {
"t-app": build(uuid, buildOutcome, "main", ["main"]),
Expand Down