lykmapipo / kue-scheduler

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

Scheduled Job Only Runs Once #122

Open tgreco opened 6 years ago

tgreco commented 6 years ago

I am using Heroku and Redis along with kue-scheduler to setup a background task. I have already enabled keyspace events but for some reason my job only runs once and then never again.

const CONFIG    = require('../../config.js');
const UTILS     = require('../utils');
const KUE       = require('kue-scheduler');
const QUEUE     = KUE.createQueue(
{
    redis:        CONFIG.REDIS_URL,
    skipConfig:   true
});

const JOB   = QUEUE.create('processKillRequests',
{
    title:      'processKillRequests',
    to:         'tomt@test.biz',
    template:   'welcome-email'
})
.save(function(err)
{
    if(!err)
    {
        UTILS.printMessage('Successfully scheduled ' + JOB.type);
    }
});

QUEUE.clear(function(error, response)
{
    var job = QUEUE.createJob("processKillRequests").priority('normal').removeOnComplete(false);
    QUEUE.every('4 minutes', job);
    QUEUE.process('processKillRequests', processKillRequests);
});

function processKillRequests(job, done)
{
    UTILS.printMessage('killRequest.processKillRequests() -> Running');
    processKillRequestsHelper()
    .then(result =>
    {
        done();
    });
}