fix: Lame fixing

This commit is contained in:
Andras Bacsai 2022-04-05 10:58:47 +02:00
parent 5684674bd7
commit 03cde08d67

View File

@ -116,54 +116,32 @@ const buildWorker = new Worker(buildQueueName, async (job) => await builder(job)
buildWorker.on('completed', async (job: Bullmq.Job) => { buildWorker.on('completed', async (job: Bullmq.Job) => {
try { try {
await asyncUntil( await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } });
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) { } catch (error) {
setTimeout(async () => {
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } });
}, 1234);
console.log(error); console.log(error);
} finally { } finally {
const workdir = `/tmp/build-sources/${job.data.repository}/${job.data.build_id}`; const workdir = `/tmp/build-sources/${job.data.repository}/${job.data.build_id}`;
if (!dev) await asyncExecShell(`rm -fr ${workdir}`); if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } });
} }
return; return;
}); });
buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => { buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => {
try { try {
await asyncUntil( await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'failed' } });
async () => {
const found = await prisma.build.findFirst({
where: { id: job.data.build_id, status: 'failed' }
});
if (!found) {
return await prisma.build.update({
where: { id: job.data.build_id },
data: { status: 'failed' }
});
}
return true;
},
100,
5
);
} catch (error) { } catch (error) {
setTimeout(async () => {
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'failed' } });
}, 1234);
console.log(error); console.log(error);
} finally { } finally {
const workdir = `/tmp/build-sources/${job.data.repository}`; const workdir = `/tmp/build-sources/${job.data.repository}`;
if (!dev) await asyncExecShell(`rm -fr ${workdir}`); if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'failed' } });
} }
await saveBuildLog({ await saveBuildLog({
line: 'Failed to deploy!', line: 'Failed to deploy!',