Skip to content

Instantly share code, notes, and snippets.

@proxygear
Last active January 15, 2020 15:06
Show Gist options
  • Save proxygear/56401a98b6ffe44f493bc1482e4baf46 to your computer and use it in GitHub Desktop.
Save proxygear/56401a98b6ffe44f493bc1482e4baf46 to your computer and use it in GitHub Desktop.
class Etl < ProcessCommand
def initialize(params)
# init if required
end
def call!
# call dangerous thing here
end
end
# Handle exception in controller
# Just let it fail
class Controller < ApplicationController
def index
MyEtl.call!
render 'everything_is_ok'
end
end
class ApplicationController
rescue_from ProcessError, :with => :error_render_method
def error_render_method
render 'everything_is_not_ok'
end
end
class ProcessCommand
def call!(*params)
new(*params).call!
rescue Exception => e
save_and_or_log(e, params)
raise ProcessError
end
def save_and_or_log(exception, params)
# implement standard way to track exception
# * logs
# * tracker
# * ticket creation
# * ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment