class Balmora

Public Class Methods

factory(state) click to toggle source

def self.create(options = {}, arguments = {})

state = Balmora::State.create(options, arguments)
return state.balmora

end

# File lib/balmora.rb, line 26
def self.factory(state)
  return self.new(state.logger, state.extension, state)
end
new(logger, extension, state) click to toggle source
# File lib/balmora.rb, line 30
def initialize(logger, extension, state)
  @logger = logger
  @extension = extension
  @state = state
end
run(task, arguments = {}, options = {}) click to toggle source
# File lib/balmora.rb, line 16
def self.run(task, arguments = {}, options = {})
  state = Balmora::State.create(options, arguments)
  state.balmora.run(task, state)
end

Public Instance Methods

run(task, state) click to toggle source
# File lib/balmora.rb, line 36
def run(task, state)
  restarts = state.config.get([:max_restarts], default: 3)

  restarts.
    times() { |index|
    begin
      dir = state.config.get(:chdir, default: Dir.pwd)
      dir = state.variables.inject(dir)
      Dir.chdir(dir) {
        commands = state.config.get([:tasks, task.to_sym(), :commands])
        run_commands(state, commands)
      }
      return 0
    rescue Restart
      @logger.debug("Restarting task (#{restarts - index} attempts left)")
      state = Balmora::State.create(@state.options, @state.arguments)
    end
  }


  raise Error.new("Maximal restart attempts count (#{restarts}) reached")
rescue Stop => stop
  @logger.debug("Stop with status #{stop.status} catched")
  return stop.status
end
run_command(state, command) click to toggle source
# File lib/balmora.rb, line 69
def run_command(state, command)
  @extension.
    create_command(state, command).
    execute()
end
run_commands(state, commands) click to toggle source
# File lib/balmora.rb, line 62
def run_commands(state, commands)
  commands.
    each() { |command|
      run_command(state, command)
    }
end