Skip to content

Commit

Permalink
Return delayed job when the SDK is not initialized (#1373)
Browse files Browse the repository at this point in the history
* Return the job when the SDK is not initialized

* Update changelog
  • Loading branch information
st0012 authored Mar 30, 2021
1 parent 8bbfda8 commit 6319ebb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sentry-delayed_job/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.3.1

- Return delayed job when the SDK is not initialized [#1373](https://github.com/getsentry/sentry-ruby/pull/1373)
- Fixes [#1334](https://github.com/getsentry/sentry-ruby/issues/1334)

## 4.3.0

- No integration-specific changes
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/lib/sentry/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module DelayedJob
class Plugin < ::Delayed::Plugin
callbacks do |lifecycle|
lifecycle.around(:invoke_job) do |job, *args, &block|
next block.call(job, *args) unless Sentry.initialized?

Sentry.with_scope do |scope|
scope.set_extras(**generate_extra(job))
scope.set_tags("delayed_job.queue" => job.queue, "delayed_job.id" => job.id.to_s)
Expand Down
18 changes: 18 additions & 0 deletions sentry-delayed_job/spec/sentry/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,21 @@ def perform
end
end


RSpec.describe Sentry::DelayedJob, "not initialized" do
class Thing
def self.invoked_method; end
end

it "doesn't swallow jobs" do
expect(Thing).to receive(:invoked_method)
Delayed::Job.delete_all
expect(Delayed::Job.count).to eq(0)

Thing.delay.invoked_method
expect(Delayed::Job.count).to eq(1)

Delayed::Worker.new.run(Delayed::Job.last)
expect(Delayed::Job.count).to eq(0)
end
end

0 comments on commit 6319ebb

Please sign in to comment.