I would like jobs.create fail if an identical job is already on the system. Is there any way to do this?
I need to run the same task every 24 hours, but some tasks can take more than 24 hours, so I need to be sure that this task has not yet been in the system (active, does not work in the queue) before adding it.
UPDATED : Well, I'm going to simplify the problem to explain it here. Suppose I have an analytics service and I have to send a report to my users once a day. Completing these reports several times (just a few cases, but this is an opportunity), take several hours even more than one day.
I need to know what current tasks are being performed to avoid duplication of tasks. I could not find anything in the API '' 'kue' '' a to find out which jobs are currently working. I also need some kind of event when more tasks are needed, and then call your producer getMoreJobs .
Maybe my approach is wrong, if so, please let me know the best way to solve my problem.
This is my simplified code:
var kue = require('kue'), cluster = require('cluster'), numCPUs = require('os').cpus().length; numCPUs = CONFIG.sync.workers || numCPUs; var jobs = kue.createQueue(); if (cluster.isMaster) { console.log('Starting master pid:' + process.pid); jobs.on('job complete', function(id){ kue.Job.get(id, function(err, job){ if (err || !job) return; job.remove(function(err){ if (err) throw err; console.log('removed completed job #%d', job.id); }); }); function getMoreJobs() { console.log('looking for more jobs...'); getOutdateReports(function (err, reports) { if (err) return setTimeout(getMoreJobs, 5 * 60 * 60 * 1000); reports.forEach(function(report) { jobs.create('reports', { id: report.id, title: report.name, params: report.params }).attempts(5).save(); }); setTimeout(getMoreJobs, 60 * 60 * 1000); }); }