Class: Proxy::RemoteExecution::Ssh::Dispatcher

Inherits:
Dynflow::Actor
  • Object
show all
Defined in:
lib/smart_proxy_remote_execution_ssh_core/dispatcher.rb

Overview

Service that handles running external commands for Actions::Command Dynflow action. It runs just one (actor) thread for all the commands running in the system and updates the Dynflow actions periodically.

Defined Under Namespace

Classes: Command

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Dispatcher

Returns a new instance of Dispatcher.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/smart_proxy_remote_execution_ssh_core/dispatcher.rb', line 34

def initialize(options = {})
  @clock                   = options[:clock] || Dynflow::Clock.spawn('proxy-dispatcher-clock')
  @logger                  = options[:logger] || Logger.new($stderr)

  @session_args = { :logger => @logger,
                    :clock => @clock,
                    :connector_class => options[:connector_class] || Connector,
                    :local_working_dir => options[:local_working_dir] || Settings.instance.local_working_dir,
                    :remote_working_dir => options[:remote_working_dir] || Settings.instance.remote_working_dir,
                    :client_private_key_file => Settings.instance.ssh_identity_key_file,
                    :refresh_interval => options[:refresh_interval] || 1 }

  @sessions = {}
end

Instance Method Details

#finish_command(command) ⇒ Object



64
65
66
67
68
# File 'lib/smart_proxy_remote_execution_ssh_core/dispatcher.rb', line 64

def finish_command(command)
  close_session(command)
rescue => exception
  handle_command_exception(command, exception)
end

#initialize_command(command) ⇒ Object



49
50
51
52
53
54
# File 'lib/smart_proxy_remote_execution_ssh_core/dispatcher.rb', line 49

def initialize_command(command)
  @logger.debug("initalizing command [#{command}]")
  open_session(command)
rescue => exception
  handle_command_exception(command, exception)
end

#kill(command) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/smart_proxy_remote_execution_ssh_core/dispatcher.rb', line 56

def kill(command)
  @logger.debug("killing command [#{command}]")
  session = @sessions[command.id]
  session.tell(:kill) if session
rescue => exception
  handle_command_exception(command, exception, false)
end