TTL exceeded not throwing job `failed` event
- Dominant language
- JavaScript
- Stars
- 9.4k
- Forks
- 858
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the event handlers in queue.js and emitter.js, then inspect the TTL setup there alongside worker registration in server.js and the pm2.json process configuration. Run the supplied reproduction and verify what happens when the 10-second TTL expires. Done means the expiration is observable through the expected failure callback so it can be recorded in the database.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, redis
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100