Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bull
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 175
    • Issues 175
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OptimalBits
  • bull
  • Issues
  • #1930
Closed
Open
Issue created Dec 09, 2020 by Administrator@rootContributor

What is the recommended way to retrieve results from completed job?

Created by: sfdcale

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`));
Assignee
Assign to
Time tracking