Skip to content

Commit

Permalink
Enforce immediate join of thread and fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lalopsb committed Mar 10, 2021
1 parent ccb0dee commit 5666bd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/exception_hunter/tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ module Tracking
# @param [User] user in the current session. (optional)
# @return [void]
def track(exception, custom_data: {}, user: nil)
open_transactions? ? create_error_within_new_thread(exception, custom_data, user) : create_error(exception, custom_data, user)
if open_transactions
create_error_within_new_thread(exception, custom_data, user)
else
create_error(exception, custom_data, user)
end

nil
end

private

def create_error_within_new_thread(exception, custom_data, user)
Thread.new do
Thread.new {
ActiveRecord::Base.connection_pool.with_connection do
create_error(exception, custom_data, user)
end
end
}.join
end

def create_error(exception, custom_data, user)
Expand Down
2 changes: 1 addition & 1 deletion spec/exception_hunter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module ExceptionHunter
context 'when the error is tracked within a transaction' do
before do
allow(ActiveRecord::Base.connection).to receive(:open_transactions).and_return(1)
allow(Thread).to receive(:new).and_yield
allow(Thread).to receive(:new).and_call_original
end

it 'creates a new error within a new thread' do
Expand Down

0 comments on commit 5666bd3

Please sign in to comment.