Class: ScoutAgent::API::Command

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

Overview

You should not need to consruct instances of this class directly as the API will handle those details for you. However, you can use the methods of these instances, returned by many API methods, to examine the success or failure of your requests.

Direct Known Subclasses

QueueCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args, input, options) ⇒ Command

Prepares and runs an API command by shelling out to name, optionally with args or input. You can also set options for the run, like :background => true.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/scout_agent/api.rb', line 26

def initialize(name, args, input, options)  # :nodoc:
  @name          = name
  @args          = args
  @input         = input
  @background    = options[:background]
  @exit_status   = nil
  @error_message = nil
  @finished      = false
  
  @background ? run_in_background : run
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the error message from the agent as a Sting. This is only set if the request was not a success?().



46
47
48
# File 'lib/scout_agent/api.rb', line 46

def error_message
  @error_message
end

#exit_statusObject (readonly) Also known as: error_code

Returns the exit status of the agent command as an Integer.



39
40
41
# File 'lib/scout_agent/api.rb', line 39

def exit_status
  @exit_status
end

Instance Method Details

#finished?Boolean

Returns true if you chose to run the request in the background and it is now complete. You can periodically poll this method to see if a background request has completed yet.

Warning: none of the other methods should be trusted until this method returns true.

Returns:

  • (Boolean)


61
62
63
# File 'lib/scout_agent/api.rb', line 61

def finished?
  @finished
end

#success?Boolean

Returns true if your request to the agent completed successfully.

Returns:

  • (Boolean)


49
50
51
# File 'lib/scout_agent/api.rb', line 49

def success?
  exit_status and exit_status.zero?
end