Module: Morpheus::Cli::ProcessesHelper
- Defined in:
- lib/morpheus/cli/mixins/processes_helper.rb
Overview
Mixin for Morpheus::Cli command classes Provides common methods for viewing process history
Class Method Summary collapse
Instance Method Summary collapse
- #api_client ⇒ Object
-
#format_process_duration(process, time_format = "%H:%M:%S") ⇒ Object
format for either ETA/Duration.
-
#format_process_error(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell.
-
#format_process_output(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell.
- #format_process_status(process, return_color = cyan) ⇒ Object
- #print_process_details(process, options = {}) ⇒ Object
- #print_process_event_details(process_event, options = {}) ⇒ Object
- #processes_interface ⇒ Object
- #wait_for_process_execution(process_id, options = {}, print_output = true) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
7 8 9 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 7 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#api_client ⇒ Object
11 12 13 14 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 11 def api_client raise "#{self.class} has not defined @api_client" if @api_client.nil? @api_client end |
#format_process_duration(process, time_format = "%H:%M:%S") ⇒ Object
format for either ETA/Duration
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 109 def format_process_duration(process, time_format="%H:%M:%S") out = "" if process['duration'] && process['duration'] > 0 out = format_duration_milliseconds(process['duration'], time_format) elsif process['statusEta'] && process['statusEta'] > 0 out = format_duration_milliseconds(process['statusEta'], time_format) elsif process['startDate'] && process['endDate'] out = format_duration(process['startDate'], process['endDate'], time_format) else "" end out end |
#format_process_error(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell
99 100 101 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 99 def format_process_error(process, max_length=20, return_color=cyan) truncate_string(process['error'].to_s.strip.gsub("\n", " "), max_length) end |
#format_process_output(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell
104 105 106 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 104 def format_process_output(process, max_length=20, return_color=cyan) truncate_string(process['output'].to_s.strip.gsub("\n", " "), max_length) end |
#format_process_status(process, return_color = cyan) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 83 def format_process_status(process, return_color=cyan) out = "" status_string = process['status'].to_s if status_string == 'complete' out << "#{green}#{status_string.upcase}#{return_color}" elsif status_string == 'failed' out << "#{red}#{status_string.upcase}#{return_color}" elsif status_string == 'expired' out << "#{red}#{status_string.upcase}#{return_color}" else out << "#{cyan}#{status_string.upcase}#{return_color}" end out end |
#print_process_details(process, options = {}) ⇒ Object
21 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 49 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 21 def print_process_details(process, ={}) description_cols = { "Process ID" => lambda {|it| it['id'] }, "Name" => lambda {|it| it['displayName'] }, "Description" => lambda {|it| it['description'] }, "Process Type" => lambda {|it| it['processType'] ? (it['processType']['name'] || it['processType']['code']) : it['processTypeName'] }, "Created By" => lambda {|it| it['createdBy'] ? (it['createdBy']['displayName'] || it['createdBy']['username']) : '' }, "Start Date" => lambda {|it| format_local_dt(it['startDate']) }, "End Date" => lambda {|it| format_local_dt(it['endDate']) }, "Duration" => lambda {|it| format_process_duration(it) }, "Status" => lambda {|it| format_process_status(it) }, # "# Events" => lambda {|it| (it['events'] || []).size() }, } print_description_list(description_cols, process, ) if process['error'] print_h2 "Error" print reset #puts format_process_error(process_event) puts process['error'].to_s.strip end if process['output'] print_h2 "Output" print reset #puts format_process_error(process_event) puts process['output'].to_s.strip end end |
#print_process_event_details(process_event, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 51 def print_process_event_details(process_event, ={}) # process_event =~ process description_cols = { "Process ID" => lambda {|it| it['processId'] }, "Event ID" => lambda {|it| it['id'] }, "Name" => lambda {|it| it['displayName'] }, "Description" => lambda {|it| it['description'] }, "Process Type" => lambda {|it| it['processType'] ? (it['processType']['name'] || it['processType']['code']) : it['processTypeName'] }, "Created By" => lambda {|it| it['createdBy'] ? (it['createdBy']['displayName'] || it['createdBy']['username']) : '' }, "Start Date" => lambda {|it| format_local_dt(it['startDate']) }, "End Date" => lambda {|it| format_local_dt(it['endDate']) }, "Duration" => lambda {|it| format_process_duration(it) }, "Status" => lambda {|it| format_process_status(it) }, } print_description_list(description_cols, process_event, ) if process_event['error'] print_h2 "Error" print reset #puts format_process_error(process_event) puts process_event['error'].to_s.strip end if process_event['output'] print_h2 "Output" print reset #puts format_process_error(process_event) puts process_event['output'].to_s.strip end end |
#processes_interface ⇒ Object
16 17 18 19 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 16 def processes_interface # get_interface('processes') api_client.processes end |
#wait_for_process_execution(process_id, options = {}, print_output = true) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 123 def wait_for_process_execution(process_id, ={}, print_output = true) refresh_interval = 10 if [:refresh_interval].to_i > 0 refresh_interval = [:refresh_interval] end refresh_display_seconds = refresh_interval % 1.0 == 0 ? refresh_interval.to_i : refresh_interval unless [:quiet] print cyan, "Refreshing every #{refresh_display_seconds} seconds until process is complete...", "\n", reset end process = processes_interface.get(process_id)['process'] while ['new','queued','pending','running'].include?(process['status']) do sleep(refresh_interval) process = processes_interface.get(process_id)['process'] end if print_output && [:quiet] != true print_h1 "Process Details", [], print_process_details(process, ) end return process end |