Skip to content

Instantly share code, notes, and snippets.

@TrumpClone
Created March 21, 2017 15:56
Show Gist options
  • Save TrumpClone/d526c47bf084ec0d41fab700252830e1 to your computer and use it in GitHub Desktop.
Save TrumpClone/d526c47bf084ec0d41fab700252830e1 to your computer and use it in GitHub Desktop.
Non KritiKal
def run_non_critical(fallback: nil, controller: nil, only_production: true)
if only_production && Rails.application.config.consider_all_requests_local
return yield
end
begin
if defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.transaction_open?
Transaction.run(requires_new: true) { yield }
else
yield
end
rescue => exception
env = controller ? controller.request.env : nil
ExceptionNotifier.notify_exception(exception, env: env)
fallback.is_a?(Proc) ? fallback.call : fallback
end
end
def raise_non_critical(*exception, **options)
run_non_critical(**options) { raise(*exception) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment