fix: attempt at avoiding double save

This commit is contained in:
tdurieux
2024-04-11 15:12:34 +01:00
parent 389030adc9
commit 05fa010349
+9 -4
View File
@@ -43,7 +43,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
} catch (_) { } catch (_) {
// ignore error // ignore error
} }
}, 500); }, 1000);
function updateProgress(obj: { status: string } | string) { function updateProgress(obj: { status: string } | string) {
const o = typeof obj === "string" ? { status: obj } : obj; const o = typeof obj === "string" ? { status: obj } : obj;
progress = o; progress = o;
@@ -65,11 +65,16 @@ export default async function (job: SandboxedJob<Repository, void>) {
throw error; throw error;
} }
} catch (error: any) { } catch (error: any) {
console.error(error);
clearInterval(statusInterval); clearInterval(statusInterval);
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
span.recordException(error as Exception); 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 { } finally {
clearInterval(statusInterval); clearInterval(statusInterval);
span.end(); span.end();