lykmapipo / kue-scheduler

A job scheduler utility for kue, backed by redis and built for node.js
246 stars 47 forks source link

Programmatically (re)start Job #95

Closed adampatarino closed 7 years ago

adampatarino commented 7 years ago

Is there a way to force a unique job to go ahead and run now, in between scheduled runs? I've tried Queue.now(job), but that only seems to work on startup, not while the server is already running.

I would want to maintain the original schedule, just force the job to run now. The other use case would be to restart / retry a job that has failed and reached its retry limit, run it now, to make sure it works, then return to it's regular schedule. Again, this applies to unique jobs.

I'm reading through your source code and I'm having trouble understanding how you get Kue to start running a job.

I'm having a restart commands come in over API / socket.io, so I'm hoping for a solution where I can do something like this:

// socket.on('restart', function(data) {
     kue.Job.get(data.jobId, function(err,job) {
        queue.now(job);
    });
// });

Right now, when I try this, I get an 'already scheduled' error thrown.

Any suggestions?

adampatarino commented 7 years ago

So, what I decided to do what to create a copy of the job that would removeOnComplete.

However, I think this feature would be really useful, especially from an API / UI perspective. Being able to manage a job's schedule and start / stop jobs via API would be really handy. @lykmapipo