debugging workers with sidekiq?
-
20-06-2021 - |
Pregunta
I converted from resque to sidekiq gem for my ruby on rails app to have less memory usage and faster response times.
The problem:
- one of my workers has an error and unlike resque-web the sidekiq-web does not show full details on the error ( like line number and cause of error )
- I'm unable to properly debug my workers, is there a workaround for this? In terminal I just get something like
error:
2012-07-12T13:26:19Z 64455 TID-ousyenaqg WARN: undefined method `perform' for #<BookInit:0x007f8c6f73f520>
More precise errors are a must have!
Solución
try change
def self.perform(params...)
to
def perform(params...)
Otros consejos
Add the next code to a rake task, and then debug it like you used to do with resque
require 'sidekiq'
require 'sidekiq/cli'
desc 'Runs Sidekiq as a rake task'
task :debug_sidekiq => :environment do
begin
cli = Sidekiq::CLI.instance
cli.parse
cli.run
rescue => e
raise e if $DEBUG
STDERR.puts e.message
STDERR.puts e.backtrace.join("\n")
exit 1
end
end
The code is taken from sidekiq/bin/sidekiq
Debugging Sidekiq With Pry :
Normally, the Sidekiq server will not start Pry when executing the statements.
You can use Sidekiq inline infrastructure for debugging Sidekiq with pry:
The Sidekiq inline infrastructure overrides perform_async and it actually calls perform instead of perform_async. This allows workers to be run inline in a testing environment.
You need to add the following to your code :
require 'sidekiq'
require 'sidekiq/testing/inline'
Now Pry will be able to call the perform method.
Note : This won't help you if you have to run jobs in threaded environment to test concurrency or performance.