Skip to content

Instantly share code, notes, and snippets.

@rud
Created January 17, 2011 09:16
Show Gist options
  • Select an option

  • Save rud/782643 to your computer and use it in GitHub Desktop.

Select an option

Save rud/782643 to your computer and use it in GitHub Desktop.
def run_import_step step_name
report_progress "Running #{step_name}" do
ImportModel.transaction do
self.send(step_name)
end
end
//...
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
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