Automattic / kue

Kue is a priority job queue backed by redis, built for node.js.
http://automattic.github.io/kue
MIT License
9.45k stars 862 forks source link

How to remove or set TTL in a .process() method #1149

Open jgervin opened 6 years ago

jgervin commented 6 years ago

Can you set the job.TTL in once inside a .process() method call? I have take over this project built on 0.8.x and I the developer did not seem to create an actual "job" via "queue.create()".

The entire code is filled with nothing but .process calls. The app works and this is the code so not sure how to set a ttl on the job if he isn't using queue.create()???? It appears initMe is called in each .process call so can I set the ttl in the initMe() method?

`jobs.process('send_callback', 10, function(job, done){
  var id = null;
  var type = null;
  var key = null;

  function initMe(){
    logMe("Got the following from payload: " + JSON.stringify(job));
    id = job.data.id;
    logMe("id: " + id);
    type = job.data.type;
    logMe("type: " + type);
    key = job.data.key;
    logMe("key: " + key);

    sendCallback();
  }

  function displayTime() {
    var str = "";

    var currentTime = new Date()
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()
    var seconds = currentTime.getSeconds()

    if (minutes < 10) {
        minutes = "0" + minutes
    }
    if (seconds < 10) {
        seconds = "0" + seconds
    }
    str += hours + ":" + minutes + ":" + seconds;
    return str;
  }

  function logMe(str){
    console.log(displayTime() + " : " + str);
    job.log(displayTime() + " : " + str);
  }

  function sendCallback(){
    params = {
      key: key,
      type: type,
      id: id
    };
    var post_data = querystring.stringify(params);
    var post_options = {
      hostname: DOMAIN,
      port: 443,
      path: "/v1/send_callback",
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': post_data.length
      }
    };
    var post_req = https.request(post_options, function(res) {
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        done();
      });
    });
    post_req.write(post_data);
    post_req.end();
  }

  initMe();
});`