Skip to content

Commit

Permalink
Fix bugs and configure limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelsky committed Dec 20, 2023
1 parent bfa5ba9 commit 12c6736
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions server/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ export async function handlerAPIDocsPoll(req, res) {
const jobId = req.params["*"];
const job = await generateDocsQueue.getJob(jobId);

if (!job) {
logger.error(`Job ${jobId} not found in queue`);
return res.status(404);
}

if (priorityCache.has(jobId)) {
await job.changePriority({
priority: priorityCache.get(jobId) - 1,
Expand All @@ -172,11 +177,6 @@ export async function handlerAPIDocsPoll(req, res) {
priorityCache.set(jobId, 99);
}

if (!job) {
logger.error(`Job ${jobId} not found in queue`);
return res.status(404);
}

if (await job.isCompleted()) {
return { status: "success" };
} else if (await job.isFailed()) {
Expand Down
14 changes: 13 additions & 1 deletion server/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const generateDocsWorker = new Worker<GenerateDocsWorkerOptions>(
concurrency: os.cpus().length - 1,
connection: redisOptions,
useWorkerThreads: true,
limiter: {
max: 2,
duration: 1000,
},
},
);

Expand Down Expand Up @@ -165,7 +169,15 @@ setInterval(async () => {
logger.warn(
`Removing ${await job.getState()} job ${job.id} because its too old`,
);
await job.remove();
try {
await job.remove();
} catch (err) {
logger.error(
`Failed to remove ${await job.getState()} job ${job.id}`,
err,
job,
);
}
}
}
}
Expand Down

0 comments on commit 12c6736

Please sign in to comment.