Class: Carrousel::Runner
- Inherits:
-
Object
- Object
- Carrousel::Runner
- Defined in:
- lib/carrousel.rb
Instance Method Summary collapse
-
#initialize(args, opts = {}) ⇒ Runner
constructor
A new instance of Runner.
-
#run ⇒ Object
def initialize.
Constructor Details
#initialize(args, opts = {}) ⇒ Runner
Returns a new instance of Runner.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/carrousel.rb', line 16 def initialize(args, opts = {}) @args = args @opts = opts @incomplete = [] @complete = [] unless @opts[:listfile].nil? lines = File.readlines(@opts[:listfile]).map(&:strip) @incomplete.concat(lines) end @incomplete.concat(@args) @opts[:statusfile] ||= generate_status_filename open_status_file p self if @opts[:debug] raise ArgumentError.new("Command option is required") if @opts[:command].nil? end |
Instance Method Details
#run ⇒ Object
def initialize
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/carrousel.rb', line 36 def run # Loop over everything in the list. Run the command. If the command fails # then we move the item to the bottom of the list. If the command # succeeds, we move the item to the completed list. If we are interrupted # in the middle of processing, we ensure that the item is saved in the # normal list, and we ensure that we write out the completed list. until @incomplete.empty? begin command = [@opts[:command], @incomplete.first].join(' ') warn "Executing command: #{command}" if @opts[:verbose] resp = system(command) warn "System response: #{resp}" if @opts[:verbose] if resp @complete << @incomplete.delete(@incomplete.first) else @incomplete.rotate! end ensure save_status_file end if @opts[:delay] > 0 warn "Sleeping for #{@opts[:delay]} seconds" if @opts[:verbose] sleep @opts[:delay] end end # until @incomplete.empty? end |