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

TTL exceeded not throwing job failed event #784

Open
zhdzmn opened this issue Dec 20, 2015 · 6 comments
Open

TTL exceeded not throwing job failed event #784

zhdzmn opened this issue Dec 20, 2015 · 6 comments

Comments

@zhdzmn
Copy link

zhdzmn commented Dec 20, 2015

Hey I have been using kue in a production application and have great results. but now that we have introduced the TTL functionality that you guys implemented I am having some problems. I will state some code to explain below

queue.js

'use strict';

var kue = require('kue'),
  express = require('express');

var queue;
var initialized =  {
  queue: false,
  app: false
};

var initQueue = function () {
  if (initialized.queue) { return console.log('Queue already initialized'); }

  queue = kue.createQueue({
    redis: {
      port: 6379,
      host: 'localhost'
    }
  });

  queue.watchStuckJobs(10 * 1000);

  queue.on('job failed', function(id){
    console.error('Job Failed', id);
    kue.Job.get(id, function(err, job){
      if (err) { return console.error('Error retrieving job', id); }

      job.remove(function (err) {
        if (err) { return console.error('Error removing failed job', id); }
        console.log('Removed failed job', id);
      });

    });
  });

  module.exports.queue = queue;
  initialized.queue = true;
};

var initApp = function () {
  if (initialized.app) { console.log('Queue GUI app already initialized'); return; }

  var kueApp = express();

  kueApp.get('/', function (req, res) {
    if (kueApp.path() === '/') {
      res.redirect('/active');
    } else {
      res.redirect('active');
    }
  });

  kueApp.use(kue.app);

  try {
    kueApp.listen(2225);
    console.log('kue listening on port 2225');
    initialized.app = true;
  } catch (e) {
    console.error(e);
    initialized.app = false;
  }
};

module.exports = {
  initQueue: initQueue,
  initApp: initApp
};

server.js

var queueSetup = require('./queue');
queueSetup.initQueue();
queueSetup.initApp();

var queue = queueSetup.queue;


queue.process('PublishingEvent', 50, publishDistribution);

var publishDistribution = function (job, done) {
  console.log('Processing distribution for publishing.');
  setTimeout(function () {
    console.log('haha I tricked you and published my self');
    done();
  }, 1000*60*3);
};

emitter.js

var queueSetup = require('./queue');
queueSetup.initQueue();
var queue = queueSetup.queue;
var emit = function () {
    var job = queue.create('PublishingEvent');

    job.on('complete', function () {
            console.log('Successfully published distribution');
        })
        .on('failed', function (errorMessage) {
            console.error('Failed to publish distribution');
            console.error(errorMessage);
        })
        .removeOnComplete(true)
        .ttl(10 * 1000)
        .save(function (err) {
            if (err) { console.error(err); }
            console.log('Put distribution publishing job on queue');
        });
}

module.exports.emitJob = emit;

pm2.json file

{
    "name": "testKUE",
    "script": "/home/zahid/apps/testKUE/server.js",
    "instances": "max",
    "exec_mode": "cluster_mode"
}

so now if i emit a job publishingEvent, it creates the job properly and fails it. l know this by looking at the gui, but I dont see it in the event callbacks i registered. This is a huge problem as I need to store in the database about this TTL exceeded error. any Idea how I can Solve this?

@zhdzmn
Copy link
Author

zhdzmn commented Dec 21, 2015

sorry for not mentioning
my environment is following

node 0.10.40
npm 1.4.28
kue 0.10.4 / kue 0.9.4

both kue has the same issue

@behrad
Copy link
Collaborator

behrad commented Dec 21, 2015

It is expected to be called as normal if the worker keeping the TTL'ed job is running... https://github.com/Automattic/kue/blob/master/lib/queue/worker.js#L77

@zhdzmn
Copy link
Author

zhdzmn commented Dec 22, 2015

for some reason it does not get called in the code I pasted. Is there anything I am missing there?

@behrad
Copy link
Collaborator

behrad commented Dec 22, 2015

Can you trace this yourself to see what is causing that?

2015-12-22 7:50 GMT+03:30 A K M Zahiduzzaman notifications@github.com:

for some reason it does not get called in the code I pasted. Is there
anything I am missing there?


Reply to this email directly or view it on GitHub
#784 (comment).

--Behrad

@ErhanAbi
Copy link

I experienced this as well and the problem was that I had the same worker replicated multiple times and after one worker's TTL exceeded, the same job was distributed again to another worker, and from here a series of errors occured (app specific errors though).

@ErhanAbi
Copy link

Wanted to mention about this on the same job being handled by multiple workers issue thread but I figured out that the TTL did the trick (I have set TTL value to a bigger value and the problem was solved). But maybe assigning the same job to another worker after TTL expired should be a problem. Or not?

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

3 participants