简体   繁体   English

Rails:sidekiq会重复这个工人吗?

[英]Rails: Will sidekiq repeat this worker?

Lets say I have this sidekiq worker: 可以说我有这个sidekiq工人:

  def perform post_id
    post = Post.find post_id
    post.do_something
  end

What would happen if the post was not found and an exception was raised? 如果找不到该帖子并且引发了异常,将会发生什么?

Will sidekiq try again? sidekiq会再试一次吗?

What would be a better design so that sidekiq would not try again without using sidekiq_options :retry => false 什么是更好的设计,以便在不使用sidekiq_options的情况下,sidekiq不会再次尝试:retry => false

Thanks! 谢谢!

If you don't want an exception raised, use find_by_id instead, which returns nil if the record doesn't exist, rather than raising an exception. 如果您不希望引发异常,请改用find_by_id ,如果记录不存在,则返回nil ,而不是引发异常。 Be sure to check for nil , though: 不过,请务必检查nil

def perform post_id
  post = Post.find_by_id post_id
  post.do_something if post
end

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

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