ruby 在Resque 1.x中有选择地删除/重试失败的作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 在Resque 1.x中有选择地删除/重试失败的作业相关的知识,希望对你有一定的参考价值。

def retry_failed_job_if
  redis = Resque.redis

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

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

    puts "Retrying job with index #{i}"
    Resque::Failure.requeue(i)
  end
end

retry_failed_job_if do |job|
  job['payload']['class'] == 'MailImport' &&
    job['exception'] == 'NoMethodError'
end
def delete_failed_job_if
  redis = Resque.redis

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

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

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

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

以上是关于ruby 在Resque 1.x中有选择地删除/重试失败的作业的主要内容,如果未能解决你的问题,请参考以下文章