Last Updated: November 08, 2021
·
2.815K
· nisanth074

A quick script to selectively remove Failed Jobs from Resque 1.x

Copy to snippet below and paste it in a rails console

def delete_if
  redis = Resque.redis

  (0...Resque::Failure.count).each do |i|
    string = redis.lindex(:failed, i)
    break if string.nil?

    job = Resque.decode(string)
    remove = yield job
    next unless remove

    redis.lrem(:failed, 1, string)
    redo
  end
end

To selectively delete a subset of failed jobs, say delete all push notification jobs that have failed because of http errors

delete_if do |job|
  job['payload']['class'] == 'SendPushNotification' &&
    job['exception'] == 'Pusher::HTTPError'
end

Here's a gist for the same https://gist.github.com/nisanth074/11332107