- Prefer to place workers in the
/app/workers
folder - Prefer to follow the Sidekiq Best Practices
- Use
raise
on theperform
method to tell Sidekiq that a job has failed when usingrescue
orResult
- Prefer to log the
error
message andbacktrace
on rescue, to help debugging
- Prefer to define worker queue as
critical
,default
orlow
, based on job proiority
- Use sidekiq-status if you wanna track job status adding
include Sidekiq::Status::Worker
to the worker
To test Sidekiq workers, prefer Sidekiq::Testing.inline!
over described_class.new.perform
.
Sidekiq::Test.inline!
change objects into JSON, simulating a production worker call, while described_class.new.perform
sends objects
Examples:
# frozen_string_literal: true
RSpec.describe(FooWorker) do
describe '#perform' do
context 'foo' do
it 'bar' do
expect { perform.new.perform }.to(change { foo }.from(nil).to(bar))
end
end
end
end
# frozen_string_literal: true
RSpec.describe(FooWorker) do
describe '#perform' do
context 'foo' do
it 'bar' do
Sidekiq::Testing.inline! do
expect { described_class.perform_async }.to(change { foo }.from(nil).to(bar))
end
end
end
end
end