Class: Blender::Driver::SerfAsync

Inherits:
Base
  • Object
show all
Defined in:
lib/blender/drivers/serf_async.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ SerfAsync

Returns a new instance of SerfAsync.



28
29
30
31
# File 'lib/blender/drivers/serf_async.rb', line 28

def initialize(config = {})
  super
  @driver = Blender::Driver::Serf.new(config)
end

Instance Method Details

#execute(tasks, hosts) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/blender/drivers/serf_async.rb', line 33

def execute(tasks, hosts)
  Log.debug("Serf Async query on #{@driver.filter_by}s [#{hosts.inspect}]")
  tasks.each do |task|
    retry_options = task.[:retry_options]
    hosts.each_slice(@driver.concurrency) do |nodes|
      Blender::Log.debug("Start query: #{task.start_query.inspect}")
      start = @driver.run_command(task.start_query.command, nodes)
      if start.exitstatus != 0 and !task.[:ignore_failure]
        raise ExecutionFailed, start.stderr
      end
      Blender::Log.debug("Using check retry options:#{retry_options}")
      Retriable.retriable(retry_options) do
        cmd = @driver.run_command(task.check_query.command, nodes)
        if cmd.exitstatus != 0 and !task.[:ignore_failure]
          raise ExecutionFailed, cmd.stderr
        end
      end
      cmd = @driver.run_command(task.stop_query.command, nodes)
      if cmd.exitstatus != 0 and !task.[:ignore_failure]
        raise ExecutionFailed, cmd.stderr
      end
    end
  end
end