fix(crawl-status): sort data

This commit is contained in:
Gergo Moricz 2024-08-13 21:55:13 +02:00
parent 8dbac0268c
commit 9252940b52

View File

@ -28,7 +28,7 @@ export async function crawlStatusController(req: Request, res: Response) {
const jobIDs = await getCrawlJobs(req.params.jobId); const jobIDs = await getCrawlJobs(req.params.jobId);
const jobs = await Promise.all(jobIDs.map(async x => { const jobs = (await Promise.all(jobIDs.map(async x => {
const job = await getScrapeQueue().getJob(x); const job = await getScrapeQueue().getJob(x);
if (process.env.USE_DB_AUTHENTICATION === "true") { if (process.env.USE_DB_AUTHENTICATION === "true") {
@ -40,7 +40,7 @@ export async function crawlStatusController(req: Request, res: Response) {
} }
return job; return job;
})); }))).sort((a, b) => a.timestamp - b.timestamp);
const jobStatuses = await Promise.all(jobs.map(x => x.getState())); const jobStatuses = await Promise.all(jobs.map(x => x.getState()));
const jobStatus = sc.cancelled ? "failed" : jobStatuses.every(x => x === "completed") ? "completed" : jobStatuses.some(x => x === "failed") ? "failed" : "active"; const jobStatus = sc.cancelled ? "failed" : jobStatuses.every(x => x === "completed") ? "completed" : jobStatuses.some(x => x === "failed") ? "failed" : "active";