Class: Ubalo::Task
- Inherits:
-
Object
- Object
- Ubalo::Task
- Defined in:
- lib/ubalo/task.rb
Instance Attribute Summary collapse
-
#arg_error ⇒ Object
readonly
Returns the value of attribute arg_error.
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#container_process ⇒ Object
readonly
Returns the value of attribute container_process.
-
#elapsed_time ⇒ Object
readonly
Returns the value of attribute elapsed_time.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#output_error ⇒ Object
readonly
Returns the value of attribute output_error.
-
#pod_name ⇒ Object
readonly
Returns the value of attribute pod_name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#submitted_at ⇒ Object
readonly
Returns the value of attribute submitted_at.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #complete? ⇒ Boolean
- #full_printable_result ⇒ Object
-
#initialize(account, label, attributes) ⇒ Task
constructor
A new instance of Task.
- #inspect ⇒ Object
- #pending? ⇒ Boolean
- #pretty_argv ⇒ Object
- #printable_result ⇒ Object
- #refresh! ⇒ Object
- #stop! ⇒ Object
- #tail_process ⇒ Object
- #url ⇒ Object
- #wait_for_process(tailer = nil) ⇒ Object
Constructor Details
#initialize(account, label, attributes) ⇒ Task
Returns a new instance of Task.
9 10 11 12 13 |
# File 'lib/ubalo/task.rb', line 9 def initialize(account, label, attributes) @account = account @label = label update_attributes(attributes) end |
Instance Attribute Details
#arg_error ⇒ Object (readonly)
Returns the value of attribute arg_error.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def arg_error @arg_error end |
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def argv @argv end |
#container_process ⇒ Object (readonly)
Returns the value of attribute container_process.
115 116 117 |
# File 'lib/ubalo/task.rb', line 115 def container_process @container_process end |
#elapsed_time ⇒ Object (readonly)
Returns the value of attribute elapsed_time.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def elapsed_time @elapsed_time end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def label @label end |
#output_error ⇒ Object (readonly)
Returns the value of attribute output_error.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def output_error @output_error end |
#pod_name ⇒ Object (readonly)
Returns the value of attribute pod_name.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def pod_name @pod_name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def state @state end |
#submitted_at ⇒ Object (readonly)
Returns the value of attribute submitted_at.
3 4 5 |
# File 'lib/ubalo/task.rb', line 3 def submitted_at @submitted_at end |
Class Method Details
.create_with_json(account, json) ⇒ Object
5 6 7 |
# File 'lib/ubalo/task.rb', line 5 def self.create_with_json(account, json) new(account, json.fetch('label'), json) end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 |
# File 'lib/ubalo/task.rb', line 70 def ==(other) label == other.label end |
#complete? ⇒ Boolean
25 26 27 |
# File 'lib/ubalo/task.rb', line 25 def complete? state == 'exited' end |
#full_printable_result ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/ubalo/task.rb', line 103 def full_printable_result s = printable_result if container_process s << container_process.printable_result end s end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/ubalo/task.rb', line 66 def inspect "#<Task #{label.inspect} state=#{state.inspect}>" end |
#pending? ⇒ Boolean
21 22 23 |
# File 'lib/ubalo/task.rb', line 21 def pending? %w{waiting running}.include?(state) end |
#pretty_argv ⇒ Object
111 112 113 |
# File 'lib/ubalo/task.rb', line 111 def pretty_argv Shellwords.join(argv) end |
#printable_result ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ubalo/task.rb', line 74 def printable_result s = "" s << " label: #{label}\n" s << " pod: #{pod_name}\n" if argv s << " argv: #{pretty_argv}\n" end if arg? if @arg_error s << "! Parse error in arg: #{@arg_error.}" else s << " arg:\n" s << Util.indent(arg.pretty_inspect) end end s << " state: #{state}\n" s << " time: #{'%.1f' % elapsed_time} s\n" if output? if @output_error s << "! Parse error in output: #{@output_error.}" else s << "output:\n" s << Util.indent(output.pretty_inspect) end end s end |
#refresh! ⇒ Object
15 16 17 18 19 |
# File 'lib/ubalo/task.rb', line 15 def refresh! update_attributes(request(:get)) rescue RestClient::ResourceNotFound raise Ubalo::Error, "Could not find task #{label.inspect}" end |
#stop! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ubalo/task.rb', line 50 def stop! tailer = Ubalo::TimedTailer.new(logger) tailer.update("Stopping #{label}...") request(:put, "/stop") refresh! logger.poll do tailer.update("Stopping #{label}...") refresh! complete? end tailer.update("Stopped #{label}. Exit code: #{container_process.exit_result}.\n") end |
#tail_process ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ubalo/task.rb', line 29 def tail_process tailer = Ubalo::TimedTailer.new(logger) wait_for_process(tailer) container_process.tail(tailer, "Running #{label}...") do refresh! complete? end tailer.update("Completed #{label}. Exit code: #{container_process.exit_result}.\n") end |
#url ⇒ Object
117 118 119 |
# File 'lib/ubalo/task.rb', line 117 def url @account.url_for(path_prefix) end |
#wait_for_process(tailer = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ubalo/task.rb', line 42 def wait_for_process(tailer = nil) logger.poll do tailer.update("Starting...") if tailer refresh! container_process end end |