lykmapipo / kue-scheduler

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

Redis database parameter breaks scheduler #42

Closed vincentheet closed 7 years ago

vincentheet commented 8 years ago

Hi,

I was trying to use kue-scheduler in one of my projects but wanted to select a Redis database since the default database 0 is already used for another library. When I configured the db to 2 I noticed that kue-scheduler is not working anymore. Running jobs with kue itself works with the db parameter but kue-scheduler is not. Here is my code:

scheduleScheduledJob(){
    let queueInstance = kue.createQueue({
      prefix: 'kue',
      redis: {
        db: 2,
        port: 6379,
        host: '192.168.99.100'
      }
    });

    let job = queueInstance
      .createJob('unique_every', {
        data: 'test'
      })
      .attempts(3)
      .backoff(true)
      .unique('unique_every');

    queueInstance.every('2 seconds', job);
    queueInstance.process('unique_every', function(job, done) {
      console.log('job executed');
      done();
    });
  },

As you can see in RDM there is a object being created in db 2. But is seems like there is no listener process watching it to execute the job.

screen shot 2016-07-19 at 17 42 08

Any ideas on this? Or maybe some pointers where the bug is so I could make a PR?

vincentheet commented 8 years ago

I did some investigation and found that the issue was in the key on which the listener subscribes for __keyevent@0__:expired the 0 in the key defines the database. I made a PR #43 in which the key is build dynamically, I do need to add tests to the PR but wanted your opinions first.

Update: I added a test to the PR to verify if everything works after selecting a custom database.

vincentheet commented 7 years ago

PR #43 has been merged in to master, closing this issue.