fix: fix queue admin

This commit is contained in:
tdurieux
2024-04-12 09:56:39 +01:00
parent b4ff27f560
commit daf3276f7f
2 changed files with 17 additions and 12 deletions
+3 -2
View File
@@ -52,6 +52,8 @@ export default async function (job: SandboxedJob<Repository, void>) {
try { try {
await repo.resetSate(RepositoryStatus.PREPARING, ""); await repo.resetSate(RepositoryStatus.PREPARING, "");
await repo.anonymize(updateProgress); await repo.anonymize(updateProgress);
clearInterval(statusInterval);
await repo.updateStatus(RepositoryStatus.READY, "");
console.log(`[QUEUE] ${job.data.repoId} is downloaded`); console.log(`[QUEUE] ${job.data.repoId} is downloaded`);
} catch (error) { } catch (error) {
updateProgress({ status: "error" }); updateProgress({ status: "error" });
@@ -72,8 +74,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
// delay to avoid double saving // delay to avoid double saving
try { try {
await repo.updateStatus(RepositoryStatus.ERROR, error.message); await repo.updateStatus(RepositoryStatus.ERROR, error.message);
} catch (ignore) { } catch (ignore) {}
}
}, 400); }, 400);
} finally { } finally {
clearInterval(statusInterval); clearInterval(statusInterval);
+14 -10
View File
@@ -42,17 +42,21 @@ router.post("/queue/:name/:repo_id", async (req, res) => {
} else { } else {
return res.status(404).json({ error: "queue_not_found" }); return res.status(404).json({ error: "queue_not_found" });
} }
const job = await queue.getJob(req.params.repo_id); let job;
if (!job) {
return res.status(404).json({ error: "job_not_found" });
}
try { try {
job = await queue.getJob(req.params.repo_id);
if (!job) {
return res.status(404).json({ error: "job_not_found" });
}
await job.retry(); await job.retry();
res.send("ok"); res.send("ok");
} catch (error) { } catch (error) {
try { try {
await job.remove(); if (job) {
queue.add(job.name, job.data, job.opts); await job.remove();
queue.add(job.name, job.data, job.opts);
}
res.send("ok"); res.send("ok");
} catch (error) { } catch (error) {
res.status(500).send("error_retrying_job"); res.status(500).send("error_retrying_job");
@@ -71,11 +75,11 @@ router.delete("/queue/:name/:repo_id", async (req, res) => {
} else { } else {
return res.status(404).json({ error: "queue_not_found" }); 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 { try {
const job = await queue.getJob(req.params.repo_id);
if (!job) {
return res.status(404).json({ error: "job_not_found" });
}
await job.remove(); await job.remove();
res.send("ok"); res.send("ok");
} catch (error) { } catch (error) {