From daf3276f7ffbb89a0d9016fa45574b52a2e161de Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 12 Apr 2024 09:56:39 +0100 Subject: [PATCH] fix: fix queue admin --- src/queue/processes/downloadRepository.ts | 5 +++-- src/server/routes/admin.ts | 24 +++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/queue/processes/downloadRepository.ts b/src/queue/processes/downloadRepository.ts index 5235eab..4cd7b9d 100644 --- a/src/queue/processes/downloadRepository.ts +++ b/src/queue/processes/downloadRepository.ts @@ -52,6 +52,8 @@ export default async function (job: SandboxedJob) { try { await repo.resetSate(RepositoryStatus.PREPARING, ""); await repo.anonymize(updateProgress); + clearInterval(statusInterval); + await repo.updateStatus(RepositoryStatus.READY, ""); console.log(`[QUEUE] ${job.data.repoId} is downloaded`); } catch (error) { updateProgress({ status: "error" }); @@ -72,8 +74,7 @@ export default async function (job: SandboxedJob) { // delay to avoid double saving try { await repo.updateStatus(RepositoryStatus.ERROR, error.message); - } catch (ignore) { - } + } catch (ignore) {} }, 400); } finally { clearInterval(statusInterval); diff --git a/src/server/routes/admin.ts b/src/server/routes/admin.ts index 61e1702..67473b6 100644 --- a/src/server/routes/admin.ts +++ b/src/server/routes/admin.ts @@ -42,17 +42,21 @@ router.post("/queue/:name/:repo_id", async (req, res) => { } else { return res.status(404).json({ error: "queue_not_found" }); } - const job = await queue.getJob(req.params.repo_id); - if (!job) { - return res.status(404).json({ error: "job_not_found" }); - } + let job; try { + job = await queue.getJob(req.params.repo_id); + if (!job) { + return res.status(404).json({ error: "job_not_found" }); + } + await job.retry(); res.send("ok"); } catch (error) { try { - await job.remove(); - queue.add(job.name, job.data, job.opts); + if (job) { + await job.remove(); + queue.add(job.name, job.data, job.opts); + } res.send("ok"); } catch (error) { res.status(500).send("error_retrying_job"); @@ -71,11 +75,11 @@ router.delete("/queue/:name/:repo_id", async (req, res) => { } else { return res.status(404).json({ error: "queue_not_found" }); } - const job = await queue.getJob(req.params.repo_id); - if (!job) { - return res.status(404).json({ error: "job_not_found" }); - } try { + const job = await queue.getJob(req.params.repo_id); + if (!job) { + return res.status(404).json({ error: "job_not_found" }); + } await job.remove(); res.send("ok"); } catch (error) {