Module: Morpheus::Cli::ExecutionRequestHelper

Included in:
Apps, Instances
Defined in:
lib/morpheus/cli/mixins/execution_request_helper.rb

Overview

Provides refreshing execution-request records by unique id (uuid)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/morpheus/cli/mixins/execution_request_helper.rb', line 6

def self.included(klass)
  klass.send :include, Morpheus::Cli::PrintHelper
end

Instance Method Details

#api_clientObject



10
11
12
13
# File 'lib/morpheus/cli/mixins/execution_request_helper.rb', line 10

def api_client
  raise "#{self.class} has not defined @api_client" if @api_client.nil?
  @api_client
end

#execution_request_interfaceObject



15
16
17
18
# File 'lib/morpheus/cli/mixins/execution_request_helper.rb', line 15

def execution_request_interface
  # get_interface('execution_request')
  api_client.execution_request
end

#wait_for_execution_request(execution_request_id, options = {}, print_output = true) ⇒ Object

refresh execution request until it is finished returns json response data of the last execution request when status reached ‘completed’ or ‘failed’



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/morpheus/cli/mixins/execution_request_helper.rb', line 22

def wait_for_execution_request(execution_request_id, options={}, print_output = true)
  refresh_interval = 10
  if options[:refresh_interval].to_i > 0
    refresh_interval = options[:refresh_interval]
  end
  execution_request = execution_request_interface.get(execution_request_id)['executionRequest']
  refresh_display_seconds = refresh_interval % 1.0 == 0 ? refresh_interval.to_i : refresh_interval
  # unless options[:quiet]
  #   print cyan, "Execution request has not yet finished. Refreshing every #{refresh_display_seconds} seconds...", "\n", reset
  # end
  while execution_request['status'] == 'pending' || execution_request['status'] == 'new' do
    sleep(refresh_interval)
    execution_request = execution_request_interface.get(execution_request_id)['executionRequest']
  end
  if print_output && options[:quiet] != true
    if execution_request['stdErr'].to_s.strip != '' && execution_request['stdErr'] != "stdin: is not a tty\n"
      print_h2 "Error"
      print execution_request['stdErr'].to_s.strip, reset, "\n"
    end
    if execution_request['stdOut'].to_s.strip != ''
      print_h2 "Output"
      print execution_request['stdOut'].to_s.strip, reset, "\n"
    end
    print reset, "\n"
  end
  return execution_request
end