Search code examples
ruby-on-railsrubysidekiq

Rails: Will sidekiq repeat this worker?


Lets say I have this sidekiq worker:

  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?

What would be a better design so that sidekiq would not try again without using sidekiq_options :retry => false

Thanks!


Solution

  • 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. Be sure to check for nil, though:

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