Keep bot jobs and harness calls from hanging

This commit is contained in:
2026-10-20 12:59:24 +01:00
parent 3e13052a25
commit 3b355d68bc
16 changed files with 420 additions and 29 deletions
+23 -8
View File
@@ -20,14 +20,29 @@ import type { LiveRelayCursor } from "./types";
* Runs in every server process, ungated.
*/
export default async function liveRelay() {
const latest = async (table: "bot_messages" | "bots_queue_updates") =>
Number(
(
await BunSQLite.sql<{ id: number }>({
sql: `SELECT MAX(id) AS id FROM ${table}`,
})
).payload?.[0]?.id,
) || 0;
/**
* A failed read starts the relay from the beginning instead of not
* starting it: clients drop what they already have.
*/
const latest = async (table: "bot_messages" | "bots_queue_updates") => {
try {
return (
Number(
(
await BunSQLite.sql<{ id: number }>({
sql: `SELECT MAX(id) AS id FROM ${table}`,
})
).payload?.[0]?.id,
) || 0
);
} catch (error) {
await logError({
title: `Live relay couldn't read ${table}`,
error,
}).catch(() => {});
return 0;
}
};
const cursor: LiveRelayCursor = {
message_id: await latest("bot_messages"),