Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sidekiq retries exhausted with arguments

I crawl leads from other sites and activate them at mine. With Sidekiq I run a HealthCheckerWorker every hour to deactivate the lead on my site unless it's still up and running on the other site.

Sometimes the HealthCheckerWorker throws an error, iE: bad URI etc... My dilemma here is that if the job fails 10 times, now in the Dead Job Queue, the lead is still considered active although it may be long gone on the other site.

I thought the solution would be to add a sidekiq_retries_exhausted block like so:

sidekiq_retries_exhausted do |lead_id|
  Lead.find(lead_id).deactivate
end

But as defined in the docs:

The hook receives the queued message as an argument. This hook is called right before Sidekiq moves the job to the DJQ.

So it only gets the message as an argument. How can I deactivate the lead after the retries are exhausted?

like image 604
davegson Avatar asked Oct 06 '14 14:10

davegson


1 Answers

The message is the entire job, including the arguments. Just pull out the arguments.

sidekiq_retries_exhausted do |msg|
  lead_id = msg['args'].first
  Lead.find(lead_id).deactivate
end
like image 58
Mike Perham Avatar answered Sep 18 '22 15:09

Mike Perham