Class: Warg::Executor::Deferred

Inherits:
Object
  • Object
show all
Defined in:
lib/warg.rb

Defined Under Namespace

Classes: CallbackFailedError, CallbacksQueue

Instance Method Summary collapse

Constructor Details

#initialize(command, run_object, hosts, order, &setup) ⇒ Deferred

Returns a new instance of Deferred.



1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
# File 'lib/warg.rb', line 1622

def initialize(command, run_object, hosts, order, &setup)
  @command = command
  @run_object = run_object
  @hosts = hosts
  @order = order
  @setup = setup

  @callbacks_queue = CallbacksQueue.new(order)

  @run_type = case @run_object
              when Script
                :run_script
              when String
                :run_command
              when Localhost::BlockProxy
                :run_block
              end
end

Instance Method Details

#and_then(&block) ⇒ Object



1645
1646
1647
1648
# File 'lib/warg.rb', line 1645

def and_then(&block)
  @callbacks_queue << block
  self
end


1641
1642
1643
# File 'lib/warg.rb', line 1641

def banner
  @run_object
end

#runObject



1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
# File 'lib/warg.rb', line 1650

def run
  execution_result = @hosts.public_send(@run_type, @run_object, order: @order, &@setup)

  execution_result = @callbacks_queue.drain(execution_result)

  if execution_result.failed?
    @command.on_failure(execution_result)
  end

  execution_result
end