Bull Queue尚未完成 [英] Bull Queue is not getting completed

查看:172
本文介绍了Bull Queue尚未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是Bull的新手.我曾尝试根据他们的文档代码来运行bull.该流程正在启动,但是我的工作尚未完成,或者不确定它是否触发了完成事件?不确定在哪里犯错

Am new to Bull.I have tried running bull based on their documentation code. The Process are starting but my job is not getting completed, or am not sure whether its triggering complete event or not? Am not sure where am making a mistake

在下面附加我的代码

const Queue = require('bull');

const myFirstQueue = new Queue('my-first-queue', 
{
  redis: { 
      port: Config.redis.port, 
      host: Config.redis.host, 
      password: Config.redis.password 
  },
});



(async function ad() {
    const job = await myFirstQueue.add({
    foo: 'bar',
  });
})();

myFirstQueue.process(async (job, data) => {
  log.debug({ job, data }, 'Job data');
  let progress = 0;
  for (let i = 0; i < 10; i++) {
    await doSomething(data);
    progress += 10;
    job.progress(progress).catch(err => {
      log.debug({ err }, 'Job progress err');
    });
    log.debug({ progress }, 'After await');
  }

  return job;
});

const doSomething = data => {
  return new Promise((resolve, reject) => {
    return resolve(data);
  });
};

myFirstQueue.on('completed', (job, result) => {
  log.debug(`Job completed with result ${job}`);
});


myFirstQueue.on('progress', (job, progress) => {
log.debug(`Job progress with result ${job} ${progress}`);
});

我可以看到进度事件处理程序中的日志,但是完整事件没有被触发.感谢您的帮助

I can see the logs which is inside the progress event handler but complete event is not getting triggered. Any help is appreciated

推荐答案

您需要从流程中调用done(),然后才会触发完成事件.

you need to call done() from process then only completed event will trigger.

myFirstQueue.process(async (job, done) => {
  const data = job.data;
  let progress = 0;
  for (let i = 0; i < 10; i++) {
    await doSomething(data);
    progress += 10;

    job.progress(progress).catch(err => {
      log.debug({ err }, 'Job progress err');
    });
  }

  done();
});

这篇关于Bull Queue尚未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆