Class: HybridPlatformsConductor::HpcPlugins::Action::Ruby

Inherits:
Action
  • Object
show all
Defined in:
lib/hybrid_platforms_conductor/hpc_plugins/action/ruby.rb

Overview

Execute Ruby commands locally

Constant Summary

Constants included from LoggerHelpers

LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Action

#initialize, #prepare_for

Methods inherited from Plugin

extend_config_dsl_with, #initialize, valid?

Methods included from LoggerHelpers

#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar

Constructor Details

This class inherits a constructor from HybridPlatformsConductor::Action

Instance Attribute Details

#nodeObject (readonly)

Give access to the node so that action can use it



61
62
63
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/ruby.rb', line 61

def node
  @node
end

Instance Method Details

#executeObject

Execute the action

API
  • This method is mandatory

API
  • @cmd_runner is accessible

API
  • @actions_executor is accessible

API
  • @action_info is accessible with the action details

API
  • @node (String) can be used to know on which node the action is to be executed

API
  • @connector (Connector or nil) can be used to access the node’s connector if the action needs remote connection

API
  • @timeout (Integer) should be used to make sure the action execution does not get past this number of seconds

API
  • @stdout_io can be used to log stdout messages

API
  • @stderr_io can be used to log stderr messages

API
  • run_cmd(String) method can be used to execute a command. See CmdRunner#run_cmd to know about the result’s signature.



51
52
53
54
55
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/ruby.rb', line 51

def execute
  log_debug "[#{@node}] - Execute local Ruby code #{@code}..."
  # TODO: Handle timeout without using Timeout which is harmful when dealing with SSH connections and multithread.
  @code.call @stdout_io, @stderr_io, self, @connector
end

#need_connector?Boolean

Do we need a connector to execute this action on a node?

Result
  • Boolean: Do we need a connector to execute this action on a node?

Returns:

  • (Boolean)


36
37
38
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/ruby.rb', line 36

def need_connector?
  @need_remote
end

#setup(info) ⇒ Object

Setup the action. This is called by the constructor itself, when an action is instantiated to be executed for a node.

API
  • This method is optional

API
  • @cmd_runner is accessible

API
  • @actions_executor is accessible

Parameters
  • info (Hash<Symbol, Object>): Properties for the Ruby action:

    • code (Proc): Ruby code to be executed. This is the default property, and can be given directly without using a Hash.

      • Parameters
        • stdout (IO): Stream in which stdout of this action should be written.

        • stderr (IO): Stream in which stderr of this action should be written.

        • action (Action): Action we can use to access other context-specific methods, such as run_cmd.

        • connector (Connector or nil): The connector to the node, or nil if none.

    • need_remote (Boolean): Do we need a remote connection to the node for this code to run? [default = false]



26
27
28
29
30
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/ruby.rb', line 26

def setup(info)
  info = { code: info } if info.is_a?(Proc)
  @need_remote = info[:need_remote] || false
  @code = info[:code]
end