Skip to content

Commit

Permalink
Don't require a DB connection, but release one if it is acquired (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeonfire committed May 7, 2022
1 parent fb80e1f commit bcfdec5
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions sentry-rails/lib/sentry/rails/background_worker.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
module Sentry
class BackgroundWorker
def _perform(&block)
# 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
block.call
ensure
# make sure the background worker returns AR connection if it accidentally acquire one during serialization
ActiveRecord::Base.connection_pool.release_connection
end
end
end

0 comments on commit bcfdec5

Please sign in to comment.