Resque: How to Delete jobs created from Rails Console

Devaraju Boddu
Railsfactory
Published in
1 min readJul 22, 2020

We have Resque.destroy method allows you to define the queue to clean up and the class name of the job type you want removed. But if we create a job from the rails console and try to delete it, it will throw an error like uninitialized constant

The following call will remove all jobs from theUpdateGraphclass:

Resque::Job.destroy(queue, 'UpdateGraph')

You can also specify arguments to filter out certain jobs of that type:

Resque::Job.destroy(queue, 'UpdateGraph', 'foo')

Consider we’ve created a job from the rails console and queued the job as below

class UpdateTestGraph
@queue = :high
def self.perform
.........
end
end
Resque.enqueue(UpdateTestGraph)

These jobs will run in a worker process where UpdateTestGraph class does not exist so it will raise a Uninitialised constant UpdateTestGraph error and this blocks the worker server from continuing to run the other jobs in the queue

At the time of deleting this job from the queue it will raise the same error. To avoid this issue and delete the job from the queue, you need to initialise the UpdateTestGraph and call the Resque.destroy method

UpdateTestGraph = 1
Resque::Job.destroy(queue, 'UpdateTestGraph')

The above solution will work for deleting the job from the rescue server

--

--

Devaraju Boddu
Railsfactory

Technical Consultant | Ruby On Rails | Java | Spring Boot | AWS