Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting for promises to resolve before running next job? #1236

Open
Popesites opened this issue Nov 25, 2019 · 0 comments
Open

Waiting for promises to resolve before running next job? #1236

Popesites opened this issue Nov 25, 2019 · 0 comments

Comments

@Popesites
Copy link

Popesites commented Nov 25, 2019

My application is structured somewhat like this:

`

router.get('/', (req, res) => {
  const node = req.body.node;
  const operation = req.body.operation;
  const value = req.body.value;
  const ids = req.body.ids;
  queue
    .create(node, {
        title: "Pausing",
        data: {
            node,
            operation,
            value,
            ids
        }
    })
    .priority("high")
    .save();
  queue.process(node, (job, done) => {
    axios.get(`https://backend-service.com/test`, job.data)
        .then(res => {
            console.log(res.status);
            done();
        })
  });
res.send("Hello World!");
});

`

Here's what the backend-service test endpoint is:

`

router.get('/test', async (req, res, next) => {
  const p = new Promise(resolve => {
    setTimeout(() => {
      console.log(req.body);
      resolve();
    }, 10000);
  });
  await p;
  return res.sendStatus(200);
});

`

The issue is that when I call this endpoint twice, with the same node parameter, what happens is it'll wait 10 seconds, then it'll console.log the response status twice right after one another.

What I want to happen is once the API is called twice, the first job should run, wait 10 seconds, then complete, then the second job should begin. Right now, both jobs are beginning at the same time essentially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant