lykmapipo / kue-scheduler

A job scheduler utility for kue, backed by redis and built for node.js
246 stars 47 forks source link

removeOnComplete(true) does not delete job when it is done #77

Open mmarshak opened 7 years ago

mmarshak commented 7 years ago

I can not make the job auto removed when complete.

I define the job as - job = Queue.createJob(type, payload) .attempts(3) .backoff( {delay: 10*1000, type:'fixed'} ) // // back of 10 seconds after each failure .priority('normal') .removeOnComplete(true);

And I use schedule to run it one time (not every) but it does not delete the job automatically. When I use just Kue instead it does. Any guidance ?

mmarshak commented 7 years ago

Does somebody have it working?

lykmapipo commented 7 years ago

@mmarshak I have the same problem and I will work to fix it.

mmarshak commented 7 years ago

Thanks

lykmapipo commented 7 years ago

@mmarshak May please add a fail test(spec) for this so that i can work around your specification.

Appreciated.

mmarshak commented 7 years ago

Hi @lykmapipo,

As I wrote in my post if I create the job, I expect that cue-scheduler will delete the job when it complete, but it does not.

job = Queue.createJob(type, payload) .attempts(3) .backoff( {delay: 10*1000, type:'fixed'} ) // // back of 10 seconds after each failure .priority('normal') .removeOnComplete(true);

So in my implementation I comment out the - .removeOnComplete(true); And in order to clean the complete job I am listening to Queue events for the event 'job complete', and then I delete the job, which works.

Bellow is the code I use for that -

// Queue events Queue.on('job enqueue', function(id, type){

    //console.log( "Queue-Job job# " +id + " got queued of type " + type );
    logKue( "Queue-Job job# " +id + " got queued of type " + type );

}).on('job complete', function(id, result){

    //console.log("Queue-Job job# " + id + " completed with data " +  util.inspect(result));
    logKue("Queue-Job job# " + id + " completed with data " +  util.inspect(result));
    //logKue("Queue-Job job# " + id + " completed ");

    // Remove the job upon its completion
    kue.Job.get(id, function(err, job){
        if (err) {
            return;
        }

        job.remove(function(err){
          if (err) {
            logError("Failed to remove job %s after it was completed, got an error %s", job.id, util.inspect(err));     
          }
          else {
            log('removed completed job #%d', job.id);
            //console.log('removed completed job #%d', job.id);
          }
        });
      });

It will be great if the .removeOnComplete(true); was doing it job as it does for the regular Kue. I am sure it will make other people easier.

Thanks

banduk commented 7 years ago

Same problem here.

Any updateon that?

rodrigooler commented 5 years ago

Same problem here.

lykmapipo commented 5 years ago

@rodrigooler Please use latest version. I merged #124. Hope it will fix the issue.