how to remove completed jobs older than x from kue

node.js

Solution

The kue API appears to have improved considerably since this question was first asked. I dug into the code a bit and this much simpler version worked for me:

var kue = require('kue');
kue.Job.rangeByState('complete', 0, someLargeNumber, 1, function(err, jobs) {
  jobs.forEach(function(job) {
    if (job.created_at < yourTimeThreshold) return;
    job.remove();  
  });
});

(Error handling is omitted for brevity's sake.)

Problem

I'm using kue for node.js and I see there is sample code for removing jobs on complete, but is there a way I can remove stale jobs older than X? I'd like to see completed jobs for a day or two so that I can review what's been happening, but for it to clean up anything older than that.

Original source