Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the list of failed Sidekiq jobs with their arguments

I am using Sidekiq for job management with a Rails APP. I would like to know how do you get the arguments of the failed jobs (Ids, Objects, error message, etc...)? On the WebUI, all you get is the nr of failed jobs. And if I understand correctly, the default is to add up all the times a given job failed. I have deployed my app and it is running on several workers. It is difficult to have to go over every single worker and try to find out, especially when you have a sidekiq.log that is many days old.

I search for an answer here and on the web. One of the closest was described on the folowing links.

How to find failed jobs list in sidekiq?

This allows to find out how many failed jobs I have over a period of time. However, I still do not know how to know exaclty what job failed and why.

Basically, I would like to somehow collect the job_ids and check periodically which ones have failed or if there is an easier way, just query Sidekiq/Redis and see what are the arguments and errors of the failed jobs.

I also visited this link: Get error message out of Sidekiq job

Here is an example job I am using

class ClassificationJob < ActiveJob::Base
 queue_as :default

 def perform(entity)
  entity.preprocess!
  entity.classify!
 end
end

I tried to modify to this

class ClassificationJob < ActiveJob::Base
 queue_as :default

 def perform(entity)
  entity.preprocess!
  entity.classify!
  store entity_id: entity.id.to_s

  entity_id = retrieve :entity_id
 end
end

But it spits the following error:

ArgumentError: You cannot include Sidekiq::Worker in an ActiveJob: ClassificationJob

Thanks,

Yannick

like image 532
Yann Avatar asked Nov 06 '15 21:11

Yann


People also ask

What is a Sidekiq job?

Workarea applications use Sidekiq as a job queuing backend to perform units of work asynchronously in the background. These jobs, which include search indexing, cache busting, and cleanup of expired data, are defined as workers .

How do I know if Sidekiq is running?

To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.

How many employees does Sidekiq have?

Today Sidekiq uses a default concurrency of 25. These means Sidekiq will spawn 25 worker threads and execute up to 25 jobs concurrently in a process.

How do I stop Sidekiq workers?

You can add the ability to stop a worker to your own code by having the worker code check regularly to see if it should stop, similar to job cancellation.


2 Answers

You are looking for retries. A "retry" is Sidekiq's term for a job which has failed and will be retried sometime in the future.

The Web UI uses the Sidekiq API documented on the API wiki page to list retries on the Retries tab:

https://github.com/mperham/sidekiq/wiki/API#retries

retries = Sidekiq::RetrySet.new
retries.each do |job|
  p [job.klass, job.args, job.jid]
end
like image 151
Mike Perham Avatar answered Sep 20 '22 08:09

Mike Perham


I've just been searching for a way to narrow down different types of failures in the console from a given queue.

After a bit of digging,

To get a list of your workers:

query = Sidekiq::Failures::FailureSet.new.map(&:item)

query.map { |item| item['class'] }.uniq # Gives you a sense of what failed
query.map { |item| item['wrapped'] }.uniq # Gives you the job's original class
query.map { |item| item['queue'] }.uniq # Gives you a name of each of the queues
query.map { |item| item['args'] }.uniq # This would give you all the argument hashes for all failures.  

The args hash has the following keys:

job_class
job_id
queue_name
arguments
locale

I think you have to have this gem for it to work: https://github.com/mhfs/sidekiq-failures

like image 43
peoplespete Avatar answered Sep 21 '22 08:09

peoplespete