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

kue-scheduler does not Save unique data until first run of job. #79

Open
gmcnaught opened this issue Jan 28, 2017 · 2 comments
Open

kue-scheduler does not Save unique data until first run of job. #79

gmcnaught opened this issue Jan 28, 2017 · 2 comments

Comments

@gmcnaught
Copy link
Collaborator

I was wrapping a pre-check for an existing job with the same unique name when I noticed a behavior I think I understand the reason for:

If you create a job:

var kue = require('kue-scheduler');
var Queue = kue.createQueue();

var client = Queue.client;
//create a job instance
var job = Queue
            .createJob('myjob', {'foo':'bar'})
            .attempts(3)
            .priority('normal')
            .unique('testUnique');

//schedule it to run every 5 seconds
Queue.every('five seconds', job,function(err,result){

 client.exists('q:unique:jobs', function(err, reply) {
    if (reply === 1) {
        console.log('Immediately exists');
    } else {
        console.log('doesn\'t exist');
    }
 //wait until the job has been scheduled for the first time
 setTimeout(function(){
  client.exists('q:unique:jobs', function(err, reply) {
    if (reply === 1) {
        console.log('exists after scheduling');
    } else {
        console.log('doesn\'t exist');
    }
  });
},6000);
});

}
);

So I noticed this, and I'm not sure how to fix it, but it does to at least be documented - as I was struggling with why if I looked in q:unique:jobs, the job would not exist until it is scheduled for the first time, but I see now that save does not get called until the first scheduled run of the job.

This creates an opportunity where you could create two jobs with the same unique constraint and it would depend on which job was scheduled last(?) which job would win in being the 'unique' job, correct?

@lykmapipo
Copy link
Owner

@gmcnaught This is because kue-scheduler rely much on redis working to achieve what it does in scheduling every jobs. So if you say a job to run every five seconds it will wait until five second for it to create a job.

In case of two job with the same unique constraint am planning to move on using redis data structure that fit for the work than just a stringified objects.

Hope we can work on this to improve documentation and implementing the desired feature.

@gmcnaught
Copy link
Collaborator Author

gmcnaught commented Feb 6, 2017 via email

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

No branches or pull requests

2 participants