diff --git a/.github/workflows/sentry_resque_test.yml b/.github/workflows/sentry_resque_test.yml index fb5c9f12e..5ea3436be 100644 --- a/.github/workflows/sentry_resque_test.yml +++ b/.github/workflows/sentry_resque_test.yml @@ -57,6 +57,14 @@ jobs: bundle install --jobs 4 --retry 3 bundle exec rake + - name: Run specs with Rails + env: + BUNDLE_GEMFILE: Gemfile_with_rails.rb + RUBYOPT: ${{ matrix.options.rubyopt }} + run: | + bundle install --jobs 4 --retry 3 + bundle exec rake + - name: Upload Coverage if: ${{ matrix.options.codecov }} uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c16c37b..22ea6a035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Bug Fixes +- Fix undefined method 'constantize' issue in `sentry-resque` ([#2248](https://github.com/getsentry/sentry-ruby/pull/2248)) - Only instantiate SessionFlusher when the SDK is enabled under the current env [#2245](https://github.com/getsentry/sentry-ruby/pull/2245) - Fixes [#2234](https://github.com/getsentry/sentry-ruby/issues/2234) diff --git a/sentry-resque/.gitignore b/sentry-resque/.gitignore index b04a8c840..63f237641 100644 --- a/sentry-resque/.gitignore +++ b/sentry-resque/.gitignore @@ -3,6 +3,7 @@ /_yardoc/ /coverage/ /doc/ +Gemfile_with_rails.rb.lock /pkg/ /spec/reports/ /tmp/ diff --git a/sentry-resque/Gemfile b/sentry-resque/Gemfile index c5c9a4e88..58c13cada 100644 --- a/sentry-resque/Gemfile +++ b/sentry-resque/Gemfile @@ -4,12 +4,6 @@ git_source(:github) { |name| "https://github.com/#{name}.git" } # Specify your gem's dependencies in sentry-ruby.gemspec gemspec gem "sentry-ruby", path: "../sentry-ruby" -gem "sentry-rails", path: "../sentry-rails" - -gem "rails" - -# For https://github.com/ruby/psych/issues/655 -gem "psych", "5.1.0" gem "resque-retry", "~> 1.8" diff --git a/sentry-resque/Gemfile_with_rails.rb b/sentry-resque/Gemfile_with_rails.rb new file mode 100644 index 000000000..bceb75350 --- /dev/null +++ b/sentry-resque/Gemfile_with_rails.rb @@ -0,0 +1,4 @@ +eval_gemfile File.expand_path("Gemfile", __dir__) + +gem "sentry-rails", path: "../sentry-rails" +gem "rails" diff --git a/sentry-resque/lib/sentry/resque.rb b/sentry-resque/lib/sentry/resque.rb index 767772d76..f204e5236 100644 --- a/sentry-resque/lib/sentry/resque.rb +++ b/sentry-resque/lib/sentry/resque.rb @@ -32,7 +32,11 @@ def record(queue, worker, payload, &block) finish_transaction(transaction, 200) rescue Exception => exception - klass = payload['class'].constantize + klass = if payload['class'].respond_to?(:constantize) + payload['class'].constantize + else + Object.const_get(payload['class']) + end raise if Sentry.configuration.resque.report_after_job_retries && defined?(::Resque::Plugins::Retry) == 'constant' && diff --git a/sentry-resque/spec/sentry/resque_spec.rb b/sentry-resque/spec/sentry/resque_spec.rb index b74f0ae27..2a4739b6f 100644 --- a/sentry-resque/spec/sentry/resque_spec.rb +++ b/sentry-resque/spec/sentry/resque_spec.rb @@ -208,11 +208,16 @@ def self.perform(msg) end end - context "with ActiveJob" do + rails_gems = begin require "rails" require "active_job" require "sentry-rails" + true + rescue LoadError + false + end + context "with ActiveJob" do class AJMessageJob < ActiveJob::Base self.queue_adapter = :resque @@ -290,7 +295,7 @@ def perform expect(event[:contexts][:"Active-Job"][:job_class]).to eq("AJFailedJob") end end - end + end if rails_gems end diff --git a/sentry-resque/spec/spec_helper.rb b/sentry-resque/spec/spec_helper.rb index af12e6103..db37bf360 100644 --- a/sentry-resque/spec/spec_helper.rb +++ b/sentry-resque/spec/spec_helper.rb @@ -4,6 +4,9 @@ require "resque" require "resque-retry" +# Allow customization of the Redis instance used for tests +Resque.redis = ENV["REDIS_URL"] if ENV.key?("REDIS_URL") + # To workaround https://github.com/steveklabnik/mono_logger/issues/13 # Note: mono_logger is resque's default logger Resque.logger = ::Logger.new(nil)