From 8b74081dfb308ed8f6bc8d147db1dc77d1551d11 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 24 Nov 2014 09:17:34 -0800 Subject: [PATCH 1/3] Rewrite false positive test The previous version of rollbar_spec.rb would pass even if `lib/resque/rollbar.rb`'s `before_first_fork` block was empty since it used the default Rollbar configuration which is synchronous. --- spec/rollbar_spec.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/rollbar_spec.rb b/spec/rollbar_spec.rb index f5081f5..f9c114c 100644 --- a/spec/rollbar_spec.rb +++ b/spec/rollbar_spec.rb @@ -1,12 +1,21 @@ require 'spec_helper' -describe Rollbar do - describe '#configuration' do - let(:configuration) { described_class.configuration } +describe 'resque-rollbar' do + describe Resque, :before_first_fork do + context 'when Rollbar has been configured to use resque' do + before do + Rollbar.configure do |config| + config.use_resque + end - describe '#use_async' do - subject { configuration.use_async } - it { is_expected.to be false } + Resque.before_first_fork.each do |hook| + hook.call + end + end + + it 'disables asyc reporting from the resque process' do + expect(Rollbar.configuration.use_async).to be_falsey + end end end end From d5f3091335fc81df2e85a489d4c5ceb0b049e211 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 24 Nov 2014 09:18:59 -0800 Subject: [PATCH 2/3] Reset Rollbar in Resque.before_first_fork Fixes cases where a `Notifier` may have been created prior to the Rollbar initializer calling `Rollbar.configure`. Previously Resque would continue to use this prematurely created `Notifier` and never use the `Configuration` defined by the initializer. See https://github.com/rollbar/rollbar-gem/issues/183 --- lib/resque/rollbar.rb | 1 + spec/rollbar_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/resque/rollbar.rb b/lib/resque/rollbar.rb index bd962ad..268465f 100644 --- a/lib/resque/rollbar.rb +++ b/lib/resque/rollbar.rb @@ -5,4 +5,5 @@ ::Rollbar.configure do |config| config.use_async = false end + ::Rollbar.reset_notifier! end diff --git a/spec/rollbar_spec.rb b/spec/rollbar_spec.rb index f9c114c..5e1a8d6 100644 --- a/spec/rollbar_spec.rb +++ b/spec/rollbar_spec.rb @@ -17,5 +17,24 @@ expect(Rollbar.configuration.use_async).to be_falsey end end + + context 'when a notifier has been created prior to configuration' do + let!(:unconfigured_notifier) { Rollbar.notifier } + + before do + Rollbar.configure do |config| + config.use_resque + end + + Resque.before_first_fork.each do |hook| + hook.call + end + end + + it 'resets the notifier' do + expect(unconfigured_notifier).to be + expect(Rollbar.notifier).not_to be(unconfigured_notifier) + end + end end end From 5b78b234ae2b275fa42cc0377611d1f503213d68 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 25 Nov 2014 19:43:09 -0800 Subject: [PATCH 3/3] Update to support only Rollbar > 1.2.x --- .travis.yml | 3 +-- gemfiles/rollbar-1.0.x.gemfile | 14 -------------- ...rollbar-0.8.x.gemfile => rollbar-1.2.x.gemfile} | 2 +- lib/resque/failure/rollbar.rb | 2 +- resque-rollbar.gemspec | 2 +- spec/resque/failure/rollbar_spec.rb | 2 +- 6 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 gemfiles/rollbar-1.0.x.gemfile rename gemfiles/{rollbar-0.8.x.gemfile => rollbar-1.2.x.gemfile} (87%) diff --git a/.travis.yml b/.travis.yml index 23e3c1e..5d656b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,7 @@ rvm: - jruby-19mode - rbx gemfile: - - gemfiles/rollbar-0.8.x.gemfile - - gemfiles/rollbar-1.0.x.gemfile + - gemfiles/rollbar-1.2.x.gemfile matrix: allow_failures: - rvm: rbx diff --git a/gemfiles/rollbar-1.0.x.gemfile b/gemfiles/rollbar-1.0.x.gemfile deleted file mode 100644 index 94af85e..0000000 --- a/gemfiles/rollbar-1.0.x.gemfile +++ /dev/null @@ -1,14 +0,0 @@ -source 'https://rubygems.org' - -gem 'rollbar', '~> 1.0.0' -gemspec :path => '../' - -platforms :rbx do - gem 'racc' - gem 'rubysl', '~> 2.0' - gem 'psych' -end - -platforms :jruby do - gem 'jruby-openssl' -end diff --git a/gemfiles/rollbar-0.8.x.gemfile b/gemfiles/rollbar-1.2.x.gemfile similarity index 87% rename from gemfiles/rollbar-0.8.x.gemfile rename to gemfiles/rollbar-1.2.x.gemfile index d3fc73c..888b480 100644 --- a/gemfiles/rollbar-0.8.x.gemfile +++ b/gemfiles/rollbar-1.2.x.gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rollbar', '~> 0.8.0' +gem 'rollbar', '~> 1.2.0' gemspec :path => '../' platforms :rbx do diff --git a/lib/resque/failure/rollbar.rb b/lib/resque/failure/rollbar.rb index 676bdcf..8f4353a 100644 --- a/lib/resque/failure/rollbar.rb +++ b/lib/resque/failure/rollbar.rb @@ -5,7 +5,7 @@ module Resque module Failure class Rollbar < Base def save - ::Rollbar.report_exception(exception, payload) + ::Rollbar.error(exception, payload) end end end diff --git a/resque-rollbar.gemspec b/resque-rollbar.gemspec index 95266db..6275b2d 100644 --- a/resque-rollbar.gemspec +++ b/resque-rollbar.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |gem| gem.require_paths = ['lib'] gem.add_dependency 'resque' - gem.add_dependency 'rollbar', '>= 0.8' + gem.add_dependency 'rollbar', '>= 1.2' gem.add_development_dependency 'rake' gem.add_development_dependency 'json' diff --git a/spec/resque/failure/rollbar_spec.rb b/spec/resque/failure/rollbar_spec.rb index 5e47bda..5dfa800 100644 --- a/spec/resque/failure/rollbar_spec.rb +++ b/spec/resque/failure/rollbar_spec.rb @@ -7,7 +7,7 @@ queue = 'test' payload = { 'class' => Object, 'args' => 89 } - expect(Rollbar).to receive(:report_exception).with(exception, payload) + expect(Rollbar.notifier).to receive(:log).with('error', exception, payload) backend = Resque::Failure::Rollbar.new(exception, worker, queue, payload) backend.save end