I am using Resque to process some background jobs on a Rails application.
The thing is that clients can cancel this jobs, so:
-
If the job is still on the queue: dequeue it
Resque.dequeue(GitHub::Jobs::UpdateNetworkGraph, 'repo:135325') -
If the job has finished: do nothing
-
If the job is running: ???
Is there a way to programmatically find the job and in case it is running tell it to stop immediatly? My main concern is to be sure that I kill the desired job, not the current one being processed as it could be a different one form the moment I ask if it is running until the moment I kill it.
I dont think that resque store the
process idof the fork process, it doeslogit though but I dont it store the process id of thechild process forkedyou can see over here in Line 139
With regard to your question of how extract the process id of the running resque job I think the way to do it inside your job itself using redis data-structure
so consider code below is your perform action for a job create using redis hash(
running_process) and add the currentprocess_idin it with the current timestampNow you can get the list of all running process by simply querying redis “running_process” hash something like this
redis.hgetall "running_process"Caveats over here If the
resquejob fail then the process id would never be clean’t fromthe hash what ever you do just make sure you cross check the
process idyou collectfrom the redis hash is actually a
running resque jobHope this help