Last active
January 15, 2020 15:06
-
-
Save proxygear/56401a98b6ffe44f493bc1482e4baf46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Etl < ProcessCommand | |
def initialize(params) | |
# init if required | |
end | |
def call! | |
# call dangerous thing here | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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