Skip to content

Commit

Permalink
Don't skip delayed_job reports if threshold is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon de Andres committed Nov 16, 2015
1 parent fb2bef2 commit 109b277
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rollbar/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ def self.invoke_job_callback
end

def self.report(e, job)
return unless job.attempts <= ::Rollbar.configuration.dj_threshold
return if skip_report?(job)

data = build_job_data(job)

::Rollbar.scope(:request => data).error(e, :use_exception_level_filters => true)
end

def self.skip_report?(job)
threshold = ::Rollbar.configuration.dj_threshold

!threshold.zero? && job.attempts > threshold
end

def self.build_job_data(job)
return nil unless ::Rollbar.configuration.report_dj_data

Expand Down
40 changes: 40 additions & 0 deletions spec/rollbar/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,44 @@ def do_job_please!(a, b)
end
end
end

describe '.skip_report' do
let(:configuration) { Rollbar.configuration }

before do
allow(configuration).to receive(:dj_threshold).and_return(5)
end

context 'configuration.dj_threshold = 0' do
let(:job) { double(attempts: 6) }

it 'returns false' do
expect(described_class.skip_report?(job)).to be(true)
end
end

context 'with attempts > configuration.dj_threshold' do
let(:job) { double(attempts: 6) }

it 'returns true' do
expect(described_class.skip_report?(job)).to be(true)
end
end

context 'with attempts < configuration.dj_threshold' do
let(:job) { double(attempts: 3) }

it 'returns false' do
expect(described_class.skip_report?(job)).to be(false)
end
end

context 'with attempts == configuration.dj_threshold' do
let(:job) { double(attempts: 4) }

it 'returns false' do
expect(described_class.skip_report?(job)).to be(false)
end
end
end
end

0 comments on commit 109b277

Please sign in to comment.