ruby - 以编程方式访问 Resque 失败作业队列

标签 ruby resque

如何编写代码来遍历 Resque 失败队列并有选择地删除作业?现在我在那里遇到了一些重要的失败,穿插在重复运行的失控工作的数千次失败之间。我想删除失控作业生成的那些。我唯一熟悉的 API 是用于排队作业的。 (我会继续 RTFMing,但我有点赶时间。)

最佳答案

我需要这样做:

# loop over all failure indices, instantiating as needed  
(Resque::Failure.count-1).downto(0).each do |error_index_number|     

  failure = Resque::Failure.all(error_index_number)

  # here :failure is the hash that has all the data about the failed job, perform any check you need here      

  if failure["error"][/regex_identifying_runaway_job/].present?        
    Resque::Failure.remove(error_index_number)
    # or
    # Resque::Failure.requeue(error_index_number)
  end

正如@Winfield 提到的,看看 Resque's failure backend很有用。

关于ruby - 以编程方式访问 Resque 失败作业队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14594819/

相关文章:

ruby-on-rails - 如何在 resque 作业中使用 ruby​​-debugger?

ruby - 来自 Bundler 的 Fresh Ruby gem - 无法加载我的 version.rb 文件?

ruby-on-rails - Rails 生成器不兼容的库

ruby - 在 Ruby 中将 %x() 评估为 True 或 False

ruby-on-rails - 从 Rails 应用程序发送短信

ruby-on-rails-3 - 在不同的应用程序中使用 Heroku 和 Resque

ruby - 如何使用 resque 发送响应

ruby-on-rails - 在 Linux Mint 中开始使用 Ruby on Rails

sql - 使用 SQL IN 和 SQL OR 运算符的 Rails 3 ActiveRecord 查询

redis - 请求使用 AUTH 连接到 Redis