class SSHKit::Custom::Runner::Abstract

Base class for all runners @abstract Subclass and override {#apply_block_to_bcks} to implement @public rubocop:disable Performance/RedundantBlockCall

Attributes

backends[RW]
options[R]
wait_interval[W]

Public Class Methods

active_backend() click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 44
def self.active_backend
  scope[:active_backend] || raise(ArgumentError, 'Backend not set')
end
active_backend=(new_backend) click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 49
def self.active_backend=(new_backend)
  scope[:active_backend] = new_backend
end
create_runner(opts) click to toggle source

Factory method to create a new runner.

# File lib/sshkit/custom/runner/abstract.rb, line 18
def self.create_runner(opts)
  opts_with_defaults = { in: :parallel }.merge(opts)

  case opts_with_defaults[:in]
  when :parallel
    Parallel
  when :sequence
    Sequential
  when :groups
    Group
  else
    raise "Don't know how to handle run style #{opts_with_defaults[:in].inspect}"
  end.new(opts_with_defaults)
end
new(options = nil) click to toggle source
# File lib/sshkit/custom/runner/abstract.rb, line 53
def initialize(options = nil)
  @options = options || {}
end
scope() click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 39
def self.scope
  @scope ||= ScopedStorage::Scope.new('sshkit_runner', scope_storage)
end
scope_storage() click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 34
def self.scope_storage
  ScopedStorage::ThreadLocalStorage
end

Public Instance Methods

active_backend() click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 58
def active_backend
  self.class.active_backend
end
active_backend=(new_backend) click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 63
def active_backend=(new_backend)
  self.class.active_backend = new_backend
end
apply_block_to_bcks(&_block) click to toggle source

@abstract

# File lib/sshkit/custom/runner/abstract.rb, line 80
def apply_block_to_bcks(&_block)
  raise SSHKit::Backend::MethodUnavailableError
end
apply_to_bck(backend, &block) click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 85
def apply_to_bck(backend, &block)
  self.active_backend = backend
  block.call(backend.host)
rescue => e
  e2 = ExecuteError.new e
  raise e2, "Exception while executing on host #{backend.host}: #{e.message}"
ensure
  self.active_backend = nil
end
do_wait() click to toggle source

@api private

# File lib/sshkit/custom/runner/abstract.rb, line 96
def do_wait
  sleep wait_interval
end
send_cmd(cmd, *args, &block) click to toggle source

Sends the given command to the backend. @param cmd [Symbol] A command that the sshkit backend supports @param args [Array] Arguments for the backend command

# File lib/sshkit/custom/runner/abstract.rb, line 71
def send_cmd(cmd, *args, &block)
  args = Array(block.call(active_backend.host)) if block
  active_backend.send(cmd, *args)
rescue => e
  e2 = ExecuteError.new e
  raise e2, "Exception while executing on host #{active_backend.host}: #{e.message}"
end

Protected Instance Methods

wait_interval() click to toggle source
# File lib/sshkit/custom/runner/abstract.rb, line 102
def wait_interval
  @wait_interval || options[:wait] || 2
end