php-resque: How to kill a specific job?

352 Views Asked by At

I am using the php-resque library and jobs can be created and tracked using the following code.

$token = Resque::enqueue('queue', 'Job', NULL, true);

$statusTracker = new Resque_Job_Status($token);
$status = $statusTracker->get();

But given the token returned by the enqueue method, how can the job be stopped?

I have found this on the project page, but it doesn't use the job token to stop a job, it uses the worker id instead.

Considering that I might have more than one worker active, how can I found the worker id that is doing the requested job?

1

There are 1 best solutions below

2
On

As far as I know, Resqueue doesn't support 'aborting' or 'stopping' jobs. But if you can somehow manage to save the cancel action in some sort of DB you'll be fine. You can do a additional check in the performAction(). Something like;

class My_Job {
    public function perform() {
        $wasCanceled = true;
        if( $wasCanceled ) {
            throw new Exception("Job was cancelled");
        }

        // Perform job stuff.
    }
}

Last but not least; this might not always work when jobs are already executed before the cancellation was done..