Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.remove not working for scheduled unqiue jobs #38

Open
arashkay opened this issue Jun 29, 2016 · 5 comments
Open

.remove not working for scheduled unqiue jobs #38

arashkay opened this issue Jun 29, 2016 · 5 comments

Comments

@arashkay
Copy link

Is there a way to do reschedule a unique job?

I have job which is scheduled to send notifications 1 hour before an activity starts. On updating the activity time I need to update the scheduled job or at least remove it and create a new one.

.remove( { unique: 'activityID1' } ) seems not working as I get this:

{ removedJobInstance: null,
  removedExpiryKey: 0,
  removedJobData: 0 }
@lykmapipo
Copy link
Owner

@tectual Please share a piece of codes that remove the schedule. But as per #L1231 it have to work.

You may also update kue-scheduler spec to fail on your scenario and i can fix it.

@sonnyt
Copy link

sonnyt commented Dec 19, 2017

@lykmapipo I am experiencing the same issue, is there a work around for this?

@syedshahzebhasnain
Copy link

+1 same case with me as well

@sonnyt
Copy link

sonnyt commented Jan 5, 2018

I ended up just using the .delay() option of Kue. Storing the jobId and then when I need to update it:

kue.Job.get(JOBID, (err, job) => {
  job.set('created_at', new Date().getTime());
  job.delay(new Date()).save();
});

I hope this helps.

@respinha
Copy link
Contributor

@lykmapipo
This happens to me whenever I attempt to remove jobs that haven't been processed yet, which is a perfectly valid use case: I could want to delete a job before its first-ever execution. In that case, it should be possible to perform such operation through the 'unique' / 'jobDataKey' keyword. And the line you quoted (#L1231) does not reflect the use case @tectual is exposing. #L1256 is the criteria used in this case. And the problem here is that if unique or jobDataKey are provided, the next() function is called with job as null, so the job instance is never deleted in the finish() function.
Again, this problem only occurs when the job has not been processed for the first time.

Example code:

const redisConfig = {
  "host": "localhost",
  "port": 6379
};
const kue = require('kue');
const queue = require('kue-scheduler').createQueue({
  redis: redisConfig
});

// schedule time is 20 seconds from now
let d = new Date();
d.setSeconds(d.getSeconds() + 20);

// creating a job
var job = queue
  .createJob('example')
  .attempts(3)
  .priority('normal')
  .unique('unique_every');

queue.schedule(d.toISOString(), job);

queue.process('example', function (job, done) {
  console.log('Job processed');
  done();
});

// attempting to remove the job before its first execution
queue.remove({
  unique: 'unique_every'
}, (err, result) => {
  console.log('Error', err);
  console.log('Result', result);
})

Output:

Error null
Result { removedJobInstance: null,
  removedExpiryKey: 0,
  removedJobData: 0 }
Job processed

There should be a way of removing the job by its unique key before it got processed, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants