Class: Ubalo::ContainerProcess

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/ubalo/container_process.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

append_config, columns, debug_mode?, decode_content, get_targz, indent, login_suggestion, normalize_pod_name, pluralize, put_targz, read_config, time_ago_in_words, write_config

Constructor Details

#initialize(account) ⇒ ContainerProcess

Returns a new instance of ContainerProcess.



13
14
15
# File 'lib/ubalo/container_process.rb', line 13

def initialize()
  @account = 
end

Instance Attribute Details

#exit_resultObject (readonly)

Returns the value of attribute exit_result.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def exit_result
  @exit_result
end

#exit_typeObject (readonly)

Returns the value of attribute exit_type.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def exit_type
  @exit_type
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def output
  @output
end

#stateObject (readonly)

Returns the value of attribute state.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def state
  @state
end

Class Method Details

.create_with_json(account, json) ⇒ Object



5
6
7
8
9
# File 'lib/ubalo/container_process.rb', line 5

def self.create_with_json(, json)
  container_process = new()
  container_process.update_attributes(json)
  container_process
end

Instance Method Details

#parse_datetime(string) ⇒ Object



53
54
55
56
57
# File 'lib/ubalo/container_process.rb', line 53

def parse_datetime(string)
  if string
    DateTime.parse(string)
  end
end

#pretty_runtimeObject



47
48
49
50
51
# File 'lib/ubalo/container_process.rb', line 47

def pretty_runtime
  if @runtime
    "%2.1f s" % @runtime
  end
end

#printable_resultObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ubalo/container_process.rb', line 35

def printable_result
  s = ""
  s << "status: #{exit_result}\n"
  s << "runtime: #{pretty_runtime}\n"

  if output and output.length > 0
    s << "stdout/stderr:\n"
    s << Util.indent(output)
  end
  s
end

#tail(tailer, message) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/ubalo/container_process.rb', line 27

def tail(tailer, message)
  logger.poll do
    result = yield
    tailer.update(message, @output)
    result
  end
end

#update_attributes(attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ubalo/container_process.rb', line 17

def update_attributes(attributes)
  @state = attributes.fetch('state')
  @runtime = attributes.fetch('runtime')
  @started_at = parse_datetime(attributes.fetch('started_at'))
  @stopped_at = parse_datetime(attributes.fetch('stopped_at'))
  @exit_type = attributes.fetch('exit_type')
  @exit_result = attributes.fetch('exit_result')
  @output = attributes.fetch('output')
end