Created
January 16, 2014 21:11
-
-
Save harrisj/8463502 to your computer and use it in GitHub Desktop.
Here's an example of doing yields in Ruby. The fail! and finished! methods set the state of the load in the DB and save the execution time
This file contains hidden or 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
def self.audit(command = 'Load') | |
unless block_given? | |
raise ArgumentError, "You can only invoke audit with a block" | |
end | |
a = nil | |
begin | |
a = Load.create :command => command, :status => 'started', :start_time => Time.now | |
yield a | |
# rescue ActiveRecord::ActiveRecordError | |
# raise | |
rescue Exception => e | |
a.fail!(e) | |
end | |
a.finished! | |
a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment