2024-04-20 19:38:05 -04:00
|
|
|
import { Request, Response } from "express";
|
|
|
|
import { getWebScraperQueue } from "../../src/services/queue-service";
|
|
|
|
|
|
|
|
export async function crawlJobStatusPreviewController(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const job = await getWebScraperQueue().getJob(req.params.jobId);
|
|
|
|
if (!job) {
|
|
|
|
return res.status(404).json({ error: "Job not found" });
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:00:38 -04:00
|
|
|
const { current, current_url, total, current_step, partialDocs } = await job.progress();
|
2024-04-20 19:38:05 -04:00
|
|
|
res.json({
|
|
|
|
status: await job.getState(),
|
|
|
|
// progress: job.progress(),
|
|
|
|
current: current,
|
|
|
|
current_url: current_url,
|
|
|
|
current_step: current_step,
|
|
|
|
total: total,
|
|
|
|
data: job.returnvalue,
|
2024-05-04 16:00:38 -04:00
|
|
|
partial_data: partialDocs ?? [],
|
2024-04-20 19:38:05 -04:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
return res.status(500).json({ error: error.message });
|
|
|
|
}
|
|
|
|
}
|