简体   繁体   English

在 Node Bull 中完成后删除作业不起作用

[英]Remove job after it is complete in Node Bull is not working

I am using node bull for scheduling.我正在使用节点公牛进行调度。 Now for my jobs i pass a cron time to it (which is a specific time and a date).现在对于我的工作,我将一个 cron 时间传递给它(这是一个特定的时间和日期)。 Now since i have provided a strict cron then it must run for only one time or even if it run second time then it must be removed from the queue (i have provided removeOnComplete: true).现在,由于我提供了一个严格的 cron,那么它必须只运行一次,或者即使它运行第二次,也必须将其从队列中删除(我提供了 removeOnComplete: true)。

But still it doesn't get removed and it runs again and my queue process this job again.但它仍然没有被删除,它再次运行,我的队列再次处理这项工作。 So i want to stop this.所以我想阻止这个。

My add job function: (data is my job data, timings is my cron timing)我的添加工作 function:(数据是我的工作数据,计时是我的 cron 计时)

public async addJob(data: any, timings: any, jobId: any) {
    console.log('adding job');
    console.log(timings);
    const job = await this.videoQueue.add(
      {data: data},
      {
        repeat: {
          cron: timings,
        },
        jobId: jobId,
        removeOnComplete: true,
     },
    );
  return job;
}

My process function:我的流程function:

this.videoQueue.process(async (job: any) => {
    // processing function for my job.
});

I am new node and node bull.我是新节点和节点公牛。 Maybe i am making a mistake but i am not able to debug it.也许我犯了一个错误,但我无法调试它。

Thanks.谢谢。

I can suggest you use node-schedule package to schedule with cron time.我可以建议你使用node-schedule package 来安排 cron 时间。 It's very easy to use actually实际上非常容易使用

    const schedule = require('node-schedule');

    const job = schedule.scheduleJob('* * * * *', function(){
        console.log('Job runned.');
        job.cancel();
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM