From 7ab5a4bfcf42166cffffcadc03eaf5311537bcb9 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 5 Apr 2022 10:30:18 +0200 Subject: [PATCH] fix: Try to update build status several times --- src/lib/queues/index.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/queues/index.ts b/src/lib/queues/index.ts index 58b9e583d..6c1cc29c2 100644 --- a/src/lib/queues/index.ts +++ b/src/lib/queues/index.ts @@ -116,7 +116,22 @@ const buildWorker = new Worker(buildQueueName, async (job) => await builder(job) buildWorker.on('completed', async (job: Bullmq.Job) => { try { - await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } }); + await asyncUntil( + async () => { + const found = await prisma.build.findFirst({ + where: { id: job.data.build_id, status: 'success' } + }); + if (!found) { + return await prisma.build.update({ + where: { id: job.data.build_id }, + data: { status: 'success' } + }); + } + return true; + }, + 100, + 5 + ); } catch (error) { console.log(error); } finally { @@ -141,7 +156,7 @@ buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => { } return true; }, - 200, + 100, 5 ); } catch (error) {