mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
fix: clear timeout on race settlement to prevent orphaned timers
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -72,19 +72,20 @@ async function runCycle(): Promise<void> {
|
|||||||
log.info({ accountCount: accounts.length }, "Processing accounts");
|
log.info({ accountCount: accounts.length }, "Processing accounts");
|
||||||
|
|
||||||
const results = await Promise.allSettled(
|
const results = await Promise.allSettled(
|
||||||
accounts.map((account) =>
|
accounts.map((account) => {
|
||||||
Promise.race([
|
let timer: ReturnType<typeof setTimeout>;
|
||||||
|
return Promise.race([
|
||||||
withTdlibMutex(account.phone, `ingest:${account.phone}`, () =>
|
withTdlibMutex(account.phone, `ingest:${account.phone}`, () =>
|
||||||
runWorkerForAccount(account)
|
runWorkerForAccount(account)
|
||||||
),
|
),
|
||||||
new Promise<never>((_, reject) =>
|
new Promise<never>((_, reject) => {
|
||||||
setTimeout(
|
timer = setTimeout(
|
||||||
() => reject(new Error(`Account ${account.phone} ingestion timed out after ${CYCLE_TIMEOUT_MS / 60_000}min`)),
|
() => reject(new Error(`Account ${account.phone} ingestion timed out after ${CYCLE_TIMEOUT_MS / 60_000}min`)),
|
||||||
CYCLE_TIMEOUT_MS
|
CYCLE_TIMEOUT_MS
|
||||||
)
|
);
|
||||||
),
|
}),
|
||||||
])
|
]).finally(() => clearTimeout(timer));
|
||||||
)
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user