fix: use per-account mutex keys in fetch/extract listeners, add cycle timeout and error logging

This commit is contained in:
2026-05-02 23:40:37 +02:00
parent e9017fc518
commit a79cb4749b
3 changed files with 58 additions and 38 deletions

View File

@@ -71,14 +71,31 @@ async function runCycle(): Promise<void> {
log.info({ accountCount: accounts.length }, "Processing accounts");
await Promise.allSettled(
const results = await Promise.allSettled(
accounts.map((account) =>
withTdlibMutex(account.phone, `ingest:${account.phone}`, () =>
runWorkerForAccount(account)
)
Promise.race([
withTdlibMutex(account.phone, `ingest:${account.phone}`, () =>
runWorkerForAccount(account)
),
new Promise<never>((_, reject) =>
setTimeout(
() => reject(new Error(`Account ${account.phone} ingestion timed out after ${CYCLE_TIMEOUT_MS / 60_000}min`)),
CYCLE_TIMEOUT_MS
)
),
])
)
);
for (let i = 0; i < results.length; i++) {
if (results[i].status === "rejected") {
log.error(
{ phone: accounts[i].phone, err: (results[i] as PromiseRejectedResult).reason },
"Account ingestion failed"
);
}
}
log.info(
{ elapsed: Math.round((Date.now() - cycleStart) / 1000) },
"Ingestion cycle complete"