如何编写代码来遍历 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/