lykmapipo / kue-scheduler

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

every doesn't work with Kue 0.10. #30

Closed skolesnyk closed 8 years ago

skolesnyk commented 8 years ago

schedule and schedule_unique works, but not 'every' .

I'm developing in loopback.

var jobCallerid =  Queue
    .createJob('unique_every', {
      to: 'callerid'
    })
    .attempts(3)
    .backoff({
      delay: 60*1000,
      type: 'fixed'
    })
    .priority('normal')
    .unique('unique_every');

  //schedule it to run every 30 seconds
 // Queue.schedule('5 seconds from now', jobCallerid);
 Queue.every('5 seconds', jobCallerid);

  //somewhere process your scheduled jobs
  Queue.process('unique_every', function (job, done) {
    console.log('queue is running..', job.id);

Also, why do scheduled finished jobs are keep piling up in redis TTL -1? Is there a point of keeping history of those jobs?

skolesnyk commented 8 years ago

Here's key in redis

{
    "type": "unique_every",
    "data": {
        "to": "callerid",
        "unique": "unique_every",
        "schedule": "RECCUR",
        "expiryKey": "d:scheduler:unique_every",
        "dataKey": "d:scheduler:data:unique_every"
    },
    "priority": 0,
    "progress": 0,
    "attempts": {
        "made": 0,
        "remaining": 3,
        "max": 3
    },
    "reccurInterval": "5 seconds",
    "backoff": {
        "delay": 60000,
        "type": "fixed"
    }
}
skolesnyk commented 8 years ago

Also, there's inconsistency between this readme.md and example you have in lib in create('every') whereas in readme you've got create('unique_every').

 *      2. create unique job
 *      var job = Queue
 *              .create('every', data)
 *              .attempts(3)
 *              .priority('normal')
 *              .unique(<unique_key>);
 *
 *      Queue.every('2 seconds', job);
lykmapipo commented 8 years ago

@skolesnyk

Hello,

There are two types of recur jobs.

1. One that keep a single instance of a job and which need unique recur key

  1. Another use multiple job instance per each schedule

You have to choose one based on your schedule scenario.

If you dont want to keep history use second option otherwise first options.

skolesnyk commented 8 years ago

@lykmapipo , Queue.every just doesn't run at all. No matter whether unique or non unique. Only scheduled jobs run. How could it be?

I can see the key for RECCUR job is created in redis, but that's it.

lykmapipo commented 8 years ago

@skolesnyk

Have you read migration guide for kue?. I bet that may be a problem. Try cross check the kue version your are using.

I will appreciate pull request to upgrade to latest kue

skolesnyk commented 8 years ago

I've downgraded to kue 0.9.6, flushall in redis. I'm using custom port settings.

var kue = require('kue-scheduler')
  , Queue = kue.createQueue({
  prefix: 'd',
  redis: {
    port: config.get("REDIS.PORT"),
    host: config.get("REDIS.HOST"),
    db: 3, // if provided select a non-default redis db
    options: {
    }
  }
});

This event never fires.

Queue.on('schedule success', function(job) {
    console.log('success', job.id);
  });

There's only one job in redis. And it's stuck.

{
    "type": "test",
    "data": {
        "to": "callerid",
        "unique": "unique_every",
        "schedule": "RECCUR",
        "expiryKey": "d:scheduler:unique_every",
        "dataKey": "d:scheduler:data:unique_every"
    },
    "priority": 0,
    "progress": 0,
    "attempts": {
        "made": 0,
        "remaining": 3,
        "max": 3
    },
    "reccurInterval": "5 seconds",
    "backoff": {
        "delay": 60000,
        "type": "fixed"
    }
}
lykmapipo commented 8 years ago

@skolesnyk

You may also listen to Schedule Error hope it will help.

skolesnyk commented 8 years ago

Of course I do. Again, nothing there. Don't you find it strange that schedule jobs work fine, but not recurring jobs?

Queue.on('schedule error', function(error) { //handle all scheduling errors here console.log(error); });

lykmapipo commented 8 years ago

@skolesnyk

Check latest version

skolesnyk commented 8 years ago

Will do!