Created
January 17, 2011 09:16
-
-
Save rud/782643 to your computer and use it in GitHub Desktop.
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 run_import_step step_name | |
| report_progress "Running #{step_name}" do | |
| ImportModel.transaction do | |
| self.send(step_name) | |
| end | |
| end | |
| //... |
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 import_updaters | |
| all_steps.each do |step_name| | |
| run_import_step(step_name) | |
| end | |
| end | |
| private | |
| def run_import_step step_name | |
| puts "Running #{step_name}" | |
| ImportModel.transaction do | |
| self.send(step_name) | |
| end | |
| rescue => e | |
| STDERR.print "\nImport error: #{e.inspect}\n#{e.backtrace.join("\n")}" | |
| STDERR.print "Please resume at step #{step_name}" | |
| exit 1 | |
| end | |
| protected | |
| def all_steps | |
| [ | |
| :link_frobnitz, | |
| :spin_really_fast_around_z_axis, | |
| :reticulate_splines, | |
| :deploy_hamsters | |
| ] | |
| end |
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 report_progress message, &block | |
| STDERR.print message | |
| if block_given? | |
| time = Benchmark.measure { yield } | |
| formatted_time = "%.2fs" % time.real | |
| STDERR.puts " - #{formatted_time}" | |
| else | |
| STDERR.puts | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment