diff --git a/src/server/tasks/board.ts b/src/server/tasks/board.ts index 33ceb00..ae1a0d9 100644 --- a/src/server/tasks/board.ts +++ b/src/server/tasks/board.ts @@ -74,7 +74,15 @@ const resetFailedAutorenders = async () => { } }; +let isUpdating = false; + const update = async () => { + if (isUpdating) { + return; + } + + isUpdating = true; + try { await checkChangelogUpdates(); } catch (err) { @@ -86,6 +94,8 @@ const update = async () => { } catch (err) { logger.error(err); } + + isUpdating = false; }; setInterval(update, BOARD_INTEGRATION_UPDATE_INTERVAL); diff --git a/src/server/tasks/portal2_sr.ts b/src/server/tasks/portal2_sr.ts index 1142641..5f2f6ed 100644 --- a/src/server/tasks/portal2_sr.ts +++ b/src/server/tasks/portal2_sr.ts @@ -7,6 +7,8 @@ export const BOARD_BASE_API = 'https://board.portal2.sr'; export const AUTORENDER_BASE_API = 'https://autorender.portal2.sr/api/v1'; +const DEFAULT_ABORT_TIMEOUT_MS = 10_000; + export type ChangelogOptions = & { id?: number; @@ -79,6 +81,7 @@ export const getChangelog = async (options?: ChangelogOptions) => { headers: { 'User-Agent': Deno.env.get('USER_AGENT')!, }, + signal: AbortSignal.timeout(DEFAULT_ABORT_TIMEOUT_MS), }); if (!res.ok) { @@ -106,6 +109,7 @@ export const fetchDemo = async (id: string | number) => { 'User-Agent': Deno.env.get('USER_AGENT')!, }, redirect: 'manual', + signal: AbortSignal.timeout(DEFAULT_ABORT_TIMEOUT_MS), }); const location = res.headers.get('Location'); @@ -121,6 +125,7 @@ export const fetchDemo = async (id: string | number) => { headers: { 'User-Agent': Deno.env.get('USER_AGENT')!, }, + signal: AbortSignal.timeout(DEFAULT_ABORT_TIMEOUT_MS), }); return { @@ -152,6 +157,7 @@ export const getInfo = async (changelogId: string) => { headers: { 'User-Agent': Deno.env.get('USER_AGENT')!, }, + signal: AbortSignal.timeout(DEFAULT_ABORT_TIMEOUT_MS), }); if (!res.ok) { diff --git a/src/server/tasks/stale.ts b/src/server/tasks/stale.ts index 3f73cb7..ef671c2 100644 --- a/src/server/tasks/stale.ts +++ b/src/server/tasks/stale.ts @@ -53,11 +53,20 @@ const checkStaleVideos = async () => { } }; +let isUpdating = false; + const update = async () => { + if (isUpdating) { + return; + } + try { + isUpdating = true; await checkStaleVideos(); } catch (err) { logger.error(err); + } finally { + isUpdating = false; } };