Skip to content

Instantly share code, notes, and snippets.

@ncdc
Last active December 24, 2015 02:59
Show Gist options
  • Save ncdc/6734300 to your computer and use it in GitHub Desktop.
Save ncdc/6734300 to your computer and use it in GitHub Desktop.
require 'parallel'
def with_gear_rotation(options={}, &block)
gears = [1,2,3]
parallel_output = Parallel.map(gears, :in_threads => 3) do |target|
rotate_and_yield(target, options, &block)
end
end
def rotate_and_yield(target, options, &block)
out = []
out << "Rotate out #{target}"
out << yield(target, options)
out << "Rotate in #{target}"
out
end
def restart(options={})
with_gear_rotation do |target, options|
restart_gear(target, options)
end
end
def restart_gear(target, options)
"restart_gear #{target}"
end
output = restart
output.each do |o|
puts o.join("\n")
puts ""
end
Rotate out 1
restart_gear 1
Rotate in 1
Rotate out 2
restart_gear 2
Rotate in 2
Rotate out 3
restart_gear 3
Rotate in 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment