简体   繁体   English

如果 sidekiq 作业在 Rails 中处于死队列中,请重试它

[英]Retry sidekiq job if it is in dead queue in rails

I want to write a cron job which fetches the sidekiq job from the dead queue and retry it, as we can do it from sidekiq's Web UI, I want to do the same through the code.我想编写一个 cron 作业,它从死队列中获取 sidekiq 作业并重试它,因为我们可以从 sidekiq 的 Web UI 中做到这一点,我想通过代码做同样的事情。

The dead queue is accessed withSidekiq::DeadSet which has a retry_all method .使用具有retry_all方法Sidekiq::DeadSet访问死队列。

Sidekiq::DeadSet.new.retry_all

This is a thin wrapper around iterating over each job in the queue and calling retry .这是对队列中每个作业的迭代并调用retry的薄包装。 SideKiq::DeadSet is Enumerable so you can use methods like select and each . SideKiq::DeadSet 是Enumerable ,因此您可以使用selecteach之类的方法。 The wiki page has a good example . wiki 页面有一个很好的例子

ds = Sidekiq::DeadSet.new

# Retry only jobs of FixedWorker class whose first argument is 123.
ds.select { |job|
  job.klass == 'FixedWorker' && job.args[0] == 123
}.map(&:retry)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM