Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent retrying for some Exception/Error on sidekiq

I have a sidekiq worker which will request 3rd party api(Mailchimp) and got some response. Sometimes it will response an error message which the api gem will raise an error.

However, those Errors are normal and no need to retry. So I would like Sidekiq prevent retry when those Errors raised.

I have tried a simply rescue, but it won't prevent the sidekiq capture the error raised.

def preform(id)
  UpdateMailchimpService.new.(id)
rescue
  Mailchimp::ListInvalidBounceMemberError
end

Any way to do this? Thanks

Update

Finally found that my problem was caused by the broken of our deploy tool(deployment failed but not realised). Actually, the Sidekiq will ignore any rescued error/exception and they are not be retried and reported to Bugsnag.

In Bugsnag's documentation, it clearly said:

Bugsnag should be installed and configured, and any unhandled exceptions will be automatically detected and should appear in your Bugsnag dashboard.

This post on github didn't have an clear explanation so that's why I am confused by this question.

like image 777
Stephen Avatar asked Jun 26 '17 07:06

Stephen


People also ask

How Sidekiq works or how would you implement Sidekiq?

Sidekiq is an open-source framework that provides efficient background processing for Ruby applications. It uses Redis as an in-memory data structure to store all of its job and operational data. It's important to be aware that Sidekiq by default doesn't do scheduling, it only executes jobs.

Does Sidekiq use Redis?

Sidekiq is usually the background job processor of choice for Ruby-on-Rails, and uses Redis as a data store for the job queues.

How do I check my job status on Sidekiq?

1 Answer. Show activity on this post. Also you can use https://github.com/utgarda/sidekiq-status gem.


2 Answers

Your assumption/example is incorrect. Do the normal Ruby thing: rescue the error and ignore it.

def perform(id)
  begin
    UpdateMailchimpService.new.(id)
  rescue NormalError
    # job will succeed normally and Sidekiq won't retry it.
  end
end
like image 160
Mike Perham Avatar answered Oct 23 '22 01:10

Mike Perham


Use retry: false advanced option:

class UpdateMailchimpWorker
  include Sidekiq::Worker
  sidekiq_options retry: false # ⇐ HERE

  def perform(id)
    UpdateMailchimpService.new.(id)
  end
end
like image 33
Aleksei Matiushkin Avatar answered Oct 22 '22 23:10

Aleksei Matiushkin