Skip to content

Instantly share code, notes, and snippets.

@vagnerzampieri
Created November 26, 2022 02:20
Show Gist options
  • Select an option

  • Save vagnerzampieri/225fe8978d18eeb226813b0e9d87cbb5 to your computer and use it in GitHub Desktop.

Select an option

Save vagnerzampieri/225fe8978d18eeb226813b0e9d87cbb5 to your computer and use it in GitHub Desktop.
rspec sidekiq_retries_exhausted without gem
# frozen_string_literal: true
module Books
class GenerateArticlesJob
include Sidekiq::Worker
sidekiq_options retry: 1
sidekiq_retries_exhausted do |message, exception|
Rollbar.error(exception, message)
end
def perform(book_id)
book = Book.find_by(id: book_id)
return if book.blank?
CreateAllArticles.call(book) # StandardError
end
end
end
# frozen_string_literal: true
describe Books::GenerateArticlesJob do
describe '#perform' do
subject { described_class.new.perform(42) }
context 'when Books::CreateAllArticles send exception' do
let(:book) { create(:book) }
let(:message) do
{
'retry' => 1,
'queue' => 'default',
'args' => [book.id],
'class' => 'Books::GenerateArticlesJob',
'jid' => '33dac36dfc0d4660f1c259c7',
'created_at' => 16_694_233_545_935_817,
'enqueued_at' => 1_669_423_379_638_612,
'error_message' => 'Error',
'error_class' => 'StandardError',
'failed_at' => 16_694_233_548_245_046,
'retry_count' => 1,
'retried_at' => 16_694_233_796_598_337
}
end
let(:exception) { StandardError.new('An error occured') }
it 'calls Rollbar' do
described_class.sidekiq_retries_exhausted_block.call(message, exception) do
expect(Rollbar).to receive(:error)
end
subject
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment