{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/kue/issues/784","labels_url":"https://api.github.com/repos/Automattic/kue/issues/784/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/kue/issues/784/comments","events_url":"https://api.github.com/repos/Automattic/kue/issues/784/events","html_url":"https://github.com/Automattic/kue/issues/784","id":123156605,"number":784,"title":"TTL exceeded not throwing job `failed` event","user":{"login":"zhdzmn","id":3144820,"avatar_url":"https://avatars.githubusercontent.com/u/3144820?v=3","gravatar_id":"","url":"https://api.github.com/users/zhdzmn","html_url":"https://github.com/zhdzmn","followers_url":"https://api.github.com/users/zhdzmn/followers","following_url":"https://api.github.com/users/zhdzmn/following{/other_user}","gists_url":"https://api.github.com/users/zhdzmn/gists{/gist_id}","starred_url":"https://api.github.com/users/zhdzmn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhdzmn/subscriptions","organizations_url":"https://api.github.com/users/zhdzmn/orgs","repos_url":"https://api.github.com/users/zhdzmn/repos","events_url":"https://api.github.com/users/zhdzmn/events{/privacy}","received_events_url":"https://api.github.com/users/zhdzmn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-20T12:03:06Z","updated_at":"2015-12-21T21:47:55Z","closed_at":null,"body":"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\r\n\r\nqueue.js\r\n``` \r\n'use strict';\r\n\r\nvar kue = require('kue'),\r\n  express = require('express');\r\n\r\nvar queue;\r\nvar initialized =  {\r\n  queue: false,\r\n  app: false\r\n};\r\n\r\nvar initQueue = function () {\r\n  if (initialized.queue) { return console.log('Queue already initialized'); }\r\n\r\n  queue = kue.createQueue({\r\n    redis: {\r\n      port: 6379,\r\n      host: 'localhost'\r\n    }\r\n  });\r\n\r\n  queue.watchStuckJobs(10 * 1000);\r\n\r\n  queue.on('job failed', function(id){\r\n    console.error('Job Failed', id);\r\n    kue.Job.get(id, function(err, job){\r\n      if (err) { return console.error('Error retrieving job', id); }\r\n\r\n      job.remove(function (err) {\r\n        if (err) { return console.error('Error removing failed job', id); }\r\n        console.log('Removed failed job', id);\r\n      });\r\n\r\n    });\r\n  });\r\n\r\n  module.exports.queue = queue;\r\n  initialized.queue = true;\r\n};\r\n\r\nvar initApp = function () {\r\n  if (initialized.app) { console.log('Queue GUI app already initialized'); return; }\r\n\r\n  var kueApp = express();\r\n\r\n  kueApp.get('/', function (req, res) {\r\n    if (kueApp.path() === '/') {\r\n      res.redirect('/active');\r\n    } else {\r\n      res.redirect('active');\r\n    }\r\n  });\r\n\r\n  kueApp.use(kue.app);\r\n\r\n  try {\r\n    kueApp.listen(2225);\r\n    console.log('kue listening on port 2225');\r\n    initialized.app = true;\r\n  } catch (e) {\r\n    console.error(e);\r\n    initialized.app = false;\r\n  }\r\n};\r\n\r\nmodule.exports = {\r\n  initQueue: initQueue,\r\n  initApp: initApp\r\n};\r\n\r\n```\r\n\r\nserver.js\r\n```\r\nvar queueSetup = require('./queue');\r\nqueueSetup.initQueue();\r\nqueueSetup.initApp();\r\n\r\nvar queue = queueSetup.queue;\r\n\r\n\r\nqueue.process('PublishingEvent', 50, publishDistribution);\r\n\r\nvar publishDistribution = function (job, done) {\r\n  console.log('Processing distribution for publishing.');\r\n  setTimeout(function () {\r\n  \tconsole.log('haha I tricked you and published my self');\r\n  \tdone();\r\n  }, 1000*60*3);\r\n};\r\n```\r\n\r\nemitter.js\r\n```\r\nvar queueSetup = require('./queue');\r\nqueueSetup.initQueue();\r\nvar queue = queueSetup.queue;\r\nvar emit = function () {\r\n\tvar job = queue.create('PublishingEvent');\r\n\r\n\tjob.on('complete', function () {\r\n\t\t\tconsole.log('Successfully published distribution');\r\n\t\t})\r\n\t\t.on('failed', function (errorMessage) {\r\n\t\t\tconsole.error('Failed to publish distribution');\r\n\t\t\tconsole.error(errorMessage);\r\n\t\t})\r\n\t\t.removeOnComplete(true)\r\n\t\t.ttl(10 * 1000)\r\n\t\t.save(function (err) {\r\n\t\t\tif (err) { console.error(err); }\r\n\t\t\tconsole.log('Put distribution publishing job on queue');\r\n\t\t});\r\n}\r\n\r\nmodule.exports.emitJob = emit;\r\n```\r\n\r\npm2.json file\r\n```\r\n{\r\n\t\"name\": \"testKUE\",\r\n\t\"script\": \"/home/zahid/apps/testKUE/server.js\",\r\n\t\"instances\": \"max\",\r\n\t\"exec_mode\": \"cluster_mode\"\r\n}\r\n```\r\n\r\n\r\nso 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?"},"comment":{"url":"https://api.github.com/repos/Automattic/kue/issues/comments/166433330","html_url":"https://github.com/Automattic/kue/issues/784#issuecomment-166433330","issue_url":"https://api.github.com/repos/Automattic/kue/issues/784","id":166433330,"user":{"login":"behrad","id":2151889,"avatar_url":"https://avatars.githubusercontent.com/u/2151889?v=3","gravatar_id":"","url":"https://api.github.com/users/behrad","html_url":"https://github.com/behrad","followers_url":"https://api.github.com/users/behrad/followers","following_url":"https://api.github.com/users/behrad/following{/other_user}","gists_url":"https://api.github.com/users/behrad/gists{/gist_id}","starred_url":"https://api.github.com/users/behrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/behrad/subscriptions","organizations_url":"https://api.github.com/users/behrad/orgs","repos_url":"https://api.github.com/users/behrad/repos","events_url":"https://api.github.com/users/behrad/events{/privacy}","received_events_url":"https://api.github.com/users/behrad/received_events","type":"User","site_admin":false},"created_at":"2015-12-21T21:47:54Z","updated_at":"2015-12-21T21:47:54Z","body":"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"}}