Skip to content

Commit

Permalink
Check if ActiveRecord connection exists before calling AR connection …
Browse files Browse the repository at this point in the history
…pool
  • Loading branch information
st0012 committed Mar 22, 2022
1 parent 16dae9d commit 1e516f5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sentry-rails/lib/sentry/rails/background_worker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module Sentry
class BackgroundWorker
def _perform(&block)
# make sure the background worker returns AR connection if it accidentally acquire one during serialization
ActiveRecord::Base.connection_pool.with_connection do
# some applications have partial or even no AR connection
if ActiveRecord::Base.connected?
# make sure the background worker returns AR connection if it accidentally acquire one during serialization
ActiveRecord::Base.connection_pool.with_connection do
block.call
end
else
block.call
end
end
Expand Down

0 comments on commit 1e516f5

Please sign in to comment.