From 05fa010349b3ee5f2f996fa2704a3845c340122c Mon Sep 17 00:00:00 2001 From: tdurieux Date: Thu, 11 Apr 2024 15:12:34 +0100 Subject: [PATCH] fix: attempt at avoiding double save --- src/queue/processes/downloadRepository.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/queue/processes/downloadRepository.ts b/src/queue/processes/downloadRepository.ts index 91322ca..5235eab 100644 --- a/src/queue/processes/downloadRepository.ts +++ b/src/queue/processes/downloadRepository.ts @@ -43,7 +43,7 @@ export default async function (job: SandboxedJob) { } catch (_) { // ignore error } - }, 500); + }, 1000); function updateProgress(obj: { status: string } | string) { const o = typeof obj === "string" ? { status: obj } : obj; progress = o; @@ -65,11 +65,16 @@ export default async function (job: SandboxedJob) { throw error; } } catch (error: any) { - console.error(error); clearInterval(statusInterval); - await repo.updateStatus(RepositoryStatus.ERROR, error.message); span.recordException(error as Exception); - console.log(`[QUEUE] ${job.data.repoId} is finished with an error`); + console.log(`[QUEUE] ${job.data.repoId} is finished with an error`, error); + setTimeout(async () => { + // delay to avoid double saving + try { + await repo.updateStatus(RepositoryStatus.ERROR, error.message); + } catch (ignore) { + } + }, 400); } finally { clearInterval(statusInterval); span.end();