Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created February 25, 2016 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeiros/6f139cf06ad36e023f46 to your computer and use it in GitHub Desktop.
Save apeiros/6f139cf06ad36e023f46 to your computer and use it in GitHub Desktop.
PassthroughExceptions = [
::NoMemoryError,
::SignalException,
::Interrupt,
::SystemExit,
]
def Thread.with_connection(*args)
start(*args) do |*inner_args|
begin
yield(*inner_args)
rescue *PassthroughExceptions
raise # do not handle PassthroughExceptions ourselves
rescue Exception => exception
ExceptionHandler.handle(exception)
ensure
ActiveRecord::Base.clear_active_connections!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment