You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using BullMQ with express server to process jobs asynchronously but confused as how to retrieve the results from completed jobs.
What I am doing currently is to listen for job completed status event and store those results in an object with job Id as key and retrieving the results from that object whenever I need it. Is there a recommended way of doing this?
I looked at documentation but couldn't find anything about how to retrieve results.
Here is the sample code:
// Kick off a new job by adding it to the work queue
app.post("/api/submitjob", async (req, res) => {
let job = await workQueue.add();
res.json({ id: job.id });
});
app.get("/api/jobstatus/:id", async (req, res) => {
let id = req.params.id;
let job = await workQueue.getJob(id);
if (job === null) {
res.status(404).end();
} else {
let state = await job.getState();
let reason = job.failedReason;
res.json({ id, state, progress, reason, result: jobIdResultMap[id] });
}
});
// You can listen to global events to get notified when jobs are processed
workQueue.on('global:completed', (jobId, result) => {
logger.log('info', `${jobId} succesfully completed`);
jobIdResultMap[jobId] = JSON.parse(result);
});
app.listen(PORT, () => console.log(`✅ API Server started: http://${HOST}:${PORT}/api/v1/endpoint`));
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am using BullMQ with express server to process jobs asynchronously but confused as how to retrieve the results from completed jobs.
What I am doing currently is to listen for job completed status event and store those results in an object with job Id as key and retrieving the results from that object whenever I need it. Is there a recommended way of doing this?
I looked at documentation but couldn't find anything about how to retrieve results.
Here is the sample code:
The text was updated successfully, but these errors were encountered: