class SBM::Runner

Constants

USAGES

Attributes

args[R]
command[R]
coordinator[R]
error[R]
output[R]
worker[R]

Public Class Methods

new(args, output = STDOUT, error = STDERR) click to toggle source
# File lib/sbm/runner.rb, line 16
def initialize(args, output = STDOUT, error = STDERR)
  @command = args.first
  @args    = args.drop(1)
  @output = output
  @error = error
  @coordinator, @worker = SBM::Coordinator.defaults
end

Public Instance Methods

clear_batch() click to toggle source
# File lib/sbm/runner.rb, line 74
def clear_batch
  batch = extract_batch!
  coordinator.clear batch
end
clear_batches() click to toggle source
# File lib/sbm/runner.rb, line 79
def clear_batches
  coordinator.clear_batches
end
clear_workers() click to toggle source
# File lib/sbm/runner.rb, line 83
def clear_workers
  coordinator.clear_workers
end
complete_batch() click to toggle source
# File lib/sbm/runner.rb, line 69
def complete_batch
  batch = extract_batch!
  coordinator.complete batch, worker
end
extract_batch!() click to toggle source
# File lib/sbm/runner.rb, line 98
def extract_batch!
  batch_name = args.shift
  if batch_name.to_s.strip.empty?
    error.puts "You must provide a batch name."
    usage
  end
  Coordinator::Batch.new(batch_name)
end
run() click to toggle source
# File lib/sbm/runner.rb, line 30
def run
  validate_command!
  send command.tr('-', '_').to_sym
end
start_batch() click to toggle source
# File lib/sbm/runner.rb, line 64
def start_batch
  batch = extract_batch!
  coordinator.start batch, worker
end
status() click to toggle source
# File lib/sbm/runner.rb, line 35
def status
  output.puts "Known Workers: #{coordinator.workers.map(&:name).sort.join(", ")}"
  output.puts "Known Batches: #{coordinator.batches.map(&:name).sort.join(", ")}"
  output.puts ""
  output.puts ""
  coordinator.batches.each do |batch|
    started   = coordinator.started_workers_for_batch   batch
    completed = coordinator.completed_workers_for_batch batch
    output.puts "Batch: #{batch}"
    output.puts "Number Started:   #{started.size}"
    output.puts "Number Completed: #{completed.size}"
    output.puts "Number Pending:   #{started.size - completed.size}"
    output.puts "---"
    output.puts "Started:   #{started.map(&:name).sort.join(", ")}"
    output.puts "Completed: #{completed.map(&:name).sort.join(", ")}"
    output.puts ""
  end
end
usage(invalid_command = false) click to toggle source
# File lib/sbm/runner.rb, line 87
def usage(invalid_command = false)
  if invalid_command
    error.puts "Invalid / unknown command - must be one of #{USAGES.keys.join(", ")}"
    error.puts "Usage: #$0 #{USAGES.keys.join("|")} [arguments]"
    exit 1
  else
    error.puts "Usage: #$0 #{command} #{USAGES[command]}".strip
    exit 1
  end
end
validate_command!() click to toggle source
# File lib/sbm/runner.rb, line 24
def validate_command!
  if command.nil? or !USAGES.has_key?(command)
    usage true
  end
end
wait_for() click to toggle source
# File lib/sbm/runner.rb, line 54
def wait_for
  batch = extract_batch!
  worker_count = args.shift.to_i
  if worker_count.zero?
    error.puts "You must provide a non-zero worker count"
    usage
  end
  coordinator.wait_for batch, worker_count
end