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
12 changes: 8 additions & 4 deletions apps/website/src/lib/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const cached = (body: string, seconds: number) => new Response(body, { headers:

/**
* Latest published release, cached at the edge for five minutes. Without a token the API allows 60 calls an hour
* per Cloudflare IP, so when it refuses, the last known release (kept a week) or the public release pages answer.
* per Cloudflare IP, so when it refuses, github.com says which release is the latest (no API call): the last known
* copy (kept a week) answers while it is still that one, the public release pages once a newer one is out. Never an
* older release just because the API was busy: the app would not see the update.
*/
export async function latestRelease(): Promise<Release> {
const cache = await caches.open('godmode-releases');
Expand All @@ -32,9 +34,11 @@ export async function latestRelease(): Promise<Release> {
await Promise.all([cache.put(fresh, cached(body, 300)), cache.put(known, cached(body, 604800))]);
return JSON.parse(body);
}
const old = await cache.match(known);
if (old) return old.json();
const release = await releaseFromPages(await latestTag());
const old = (await cache.match(known)?.then((r) => r?.json() as Promise<Release> | undefined)) ?? null;
const tag = await latestTag().catch(() => null);
if (old && (!tag || old.tag_name === tag)) return old;
if (!tag) throw new Error(`GitHub latest release: API ${res?.status ?? 'unreachable'}, release page unreadable`);
const release = await releaseFromPages(tag);
await cache.put(fresh, cached(JSON.stringify(release), 300));
return release;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/scheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ describe("triggering", () => {
});

test("a computer that starts standing in runs the automations that came due since the primary went, once", async () => {
// Only this test's automations: earlier ones may come due at the time of day the suite runs.
exec("UPDATE routines SET enabled = 0");
const hourly = createRoutine({ agentId: agent.id, name: "Hourly", cron: "0 * * * *", timezone: "UTC", prompt: "hourly" });
const ranThere = createRoutine({ agentId: agent.id, name: "Ran there", cron: "0 * * * *", timezone: "UTC", prompt: "done there" });
const before = createRoutine({ agentId: agent.id, name: "Before", cron: "0 0 1 1 *", timezone: "UTC", prompt: "yearly" });
Expand Down
Loading