Class: Ubalo::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/ubalo/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(, label, attributes)
  @account = 
  @label = label
  update_attributes(attributes)
end

Instance Attribute Details

#arg_errorObject (readonly)

Returns the value of attribute arg_error.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def arg_error
  @arg_error
end

#argvObject (readonly)

Returns the value of attribute argv.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def argv
  @argv
end

#container_processObject (readonly)

Returns the value of attribute container_process.



108
109
110
# File 'lib/ubalo/task.rb', line 108

def container_process
  @container_process
end

#elapsed_timeObject (readonly)

Returns the value of attribute elapsed_time.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def elapsed_time
  @elapsed_time
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def label
  @label
end

#output_errorObject (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_nameObject (readonly)

Returns the value of attribute pod_name.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def pod_name
  @pod_name
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def state
  @state
end

#submitted_atObject (readonly)

Returns the value of attribute submitted_at.



3
4
5
# File 'lib/ubalo/task.rb', line 3

def 
  @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(, json)
  new(, json.fetch('label'), json)
end

Instance Method Details

#==(other) ⇒ Object



65
66
67
# File 'lib/ubalo/task.rb', line 65

def ==(other)
  label == other.label
end

#complete?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ubalo/task.rb', line 25

def complete?
  state == 'exited'
end

#full_printable_resultObject



96
97
98
99
100
101
102
# File 'lib/ubalo/task.rb', line 96

def full_printable_result
  s = printable_result
  if container_process
    s << container_process.printable_result
  end
  s
end

#inspectObject



61
62
63
# File 'lib/ubalo/task.rb', line 61

def inspect
  "#<Task #{label.inspect} state=#{state.inspect}>"
end

#pending?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ubalo/task.rb', line 21

def pending?
  %w{waiting running}.include?(state)
end

#pretty_argvObject



104
105
106
# File 'lib/ubalo/task.rb', line 104

def pretty_argv
  Shellwords.join(argv)
end

#printable_resultObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ubalo/task.rb', line 69

def printable_result
  s = ""
  s << " label: #{label}\n"
  s << "   pod: #{pod_name}\n"
  s << "  argv: #{pretty_argv}\n"
  if arg?
    if @arg_error
      s << "! Parse error in arg: #{@arg_error.message}"
    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.message}"
    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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ubalo/task.rb', line 46

def stop!
  tailer = Ubalo::TimedTailer.new(logger)

  tailer.update("Stopping #{label}...")
  request(:put, "/stop")

  logger.poll do
    tailer.update("Stopping #{label}...")
    refresh!
    complete?
  end

  tailer.update("Stopped #{label}. Exit code: #{container_process.exit_result}.\n")
end

#tail_processObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ubalo/task.rb', line 29

def tail_process
  tailer = Ubalo::TimedTailer.new(logger)

  logger.poll do
    tailer.update("Starting...")
    refresh!
    container_process
  end

  container_process.tail(tailer, "Running #{label}...") do
    refresh!
    complete?
  end

  tailer.update("Completed #{label}. Exit code: #{container_process.exit_result}.\n")
end

#urlObject



110
111
112
# File 'lib/ubalo/task.rb', line 110

def url
  @account.url_for(path_prefix)
end