繁体   English   中英

在KUE节点js中更新作业状态

[英]Updating job status in KUE node js

我创建一个工作:

var kue = require('kue');
var queue = kue.createQueue();

//name of the queue is myQueue
var job = queue.create('myQueue', {
    from: 'process1',
    type: 'testMessage',
    data: {
        msg: 'Hello world!'
    }
}).save(function(err) {
    if (err) {
        console.log('Unable to save ' + err);
    } else {
        console.log('Job ' + job.id + ' saved to the queue.');
    }
});

有什么办法可以自己更新工作状态(即活动,失败,进行中)? 因此,例如:

消费者接工作:

queue.process('myQueue', function(job, done){
  console.log('IN HERE', job.state) // returns function
});

这是从上面返回的函数:

function ( state, fn ) {
  if( 0 == arguments.length ) return this._state;
  var client   = this.client
    , fn       = fn || noop;
  var oldState = this._state;
  var multi    = client.multi();

我想对工作状态进行硬编码,例如job.state = 'failed'并允许自己在需要时更新工作状态?

在ue市有可能吗?

快速答案,是的,您可以使用job.failed()或将错误发送回完成。

queue.process('myQueue', function(job, done){
  console.log('IN HERE', job.state) // returns function

  job.failed();
  done(new Error('bad'));
});

但是,听起来您想自己处理。 您可以像这样设置自己的功能。

queue.on('job enqueue', function(id, type){
   console.log( 'Job %s got queued of type %s', id, type );
   kue.Job.get(id, function(err, job){
      if (err) return;
      // do your custom processing here
      if( something was processed ){
         job.complete();
      }else{
         job.failed();
      }
   });
});

您还可以使用以下几个选项。

job.inactive(); 
job.active();
job.complete();
job.delayed();

此页面上有一些示例。 https://github.com/Automattic/kue

暂无
暂无

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

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