Class: Ufo::Ps::Task
- Inherits:
-
Object
- Object
- Ufo::Ps::Task
- Defined in:
- lib/ufo/ps/task.rb
Constant Summary collapse
- @@extra_columns =
false
Class Method Summary collapse
Instance Method Summary collapse
- #container_instance_arn ⇒ Object
- #extra_columns ⇒ Object
-
#hide? ⇒ Boolean
started_at=2018-07-05 21:52:15 -0700, stopping_at=2018-07-05 22:03:44 -0700, stopped_at=2018-07-05 22:03:45 -0700,.
- #id ⇒ Object
-
#initialize(task) ⇒ Task
constructor
A new instance of Task.
- #name ⇒ Object
- #notes ⇒ Object
- #relative_time(start_time) ⇒ Object
- #release ⇒ Object
- #started ⇒ Object
- #status ⇒ Object
- #time(value) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(task) ⇒ Task
Returns a new instance of Task.
9 10 11 |
# File 'lib/ufo/ps/task.rb', line 9 def initialize(task) @task = task end |
Class Method Details
.extra_columns ⇒ Object
95 96 97 |
# File 'lib/ufo/ps/task.rb', line 95 def self.extra_columns @@extra_columns end |
.extra_columns=(val) ⇒ Object
91 92 93 |
# File 'lib/ufo/ps/task.rb', line 91 def self.extra_columns=(val) @@extra_columns = val end |
.header ⇒ Object
3 4 5 6 7 |
# File 'lib/ufo/ps/task.rb', line 3 def self.header header = %w[Id Name Release Started Status Notes] header << "Container Instance" if extra_columns header end |
Instance Method Details
#container_instance_arn ⇒ Object
29 30 31 |
# File 'lib/ufo/ps/task.rb', line 29 def container_instance_arn @task['container_instance_arn'].split('/').last end |
#extra_columns ⇒ Object
99 100 101 |
# File 'lib/ufo/ps/task.rb', line 99 def extra_columns self.class.extra_columns end |
#hide? ⇒ Boolean
started_at=2018-07-05 21:52:15 -0700, stopping_at=2018-07-05 22:03:44 -0700, stopped_at=2018-07-05 22:03:45 -0700,
54 55 56 57 |
# File 'lib/ufo/ps/task.rb', line 54 def hide? stopped_at = time(@task["stopped_at"]) status == "STOPPED" && stopped_at < Time.now - 60 * 5 end |
#id ⇒ Object
19 20 21 |
# File 'lib/ufo/ps/task.rb', line 19 def id @task['task_arn'].split('/').last.split('-').first end |
#name ⇒ Object
23 24 25 26 27 |
# File 'lib/ufo/ps/task.rb', line 23 def name @task["overrides"]["container_overrides"].first["name"] rescue NoMethodError @task["containers"].first["name"] end |
#notes ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/ufo/ps/task.rb', line 63 def notes return unless @task["stopped_reason"] if @task["stopped_reason"] =~ /Task failed ELB health checks/ "Failed ELB health check" else @task["stopped_reason"] end end |
#relative_time(start_time) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ufo/ps/task.rb', line 74 def relative_time(start_time) diff_seconds = Time.now - start_time case diff_seconds when 0 .. 59 "#{diff_seconds.to_i} seconds ago" when 60 .. (3600-1) "#{(diff_seconds/60).to_i} minutes ago" when 3600 .. (3600*24-1) "#{(diff_seconds/3600).to_i} hours ago" when (3600*24) .. (3600*24*30) "#{(diff_seconds/(3600*24)).to_i} days ago" else start_time.strftime("%m/%d/%Y") end end |
#release ⇒ Object
33 34 35 |
# File 'lib/ufo/ps/task.rb', line 33 def release @task["task_definition_arn"].split('/').last end |
#started ⇒ Object
37 38 39 40 41 |
# File 'lib/ufo/ps/task.rb', line 37 def started started = time(@task["started_at"]) return "PENDING" unless started relative_time(started) end |
#status ⇒ Object
59 60 61 |
# File 'lib/ufo/ps/task.rb', line 59 def status @task["last_status"] end |
#time(value) ⇒ Object
43 44 45 46 47 |
# File 'lib/ufo/ps/task.rb', line 43 def time(value) Time.parse(value.to_s) rescue ArgumentError nil end |
#to_a ⇒ Object
13 14 15 16 17 |
# File 'lib/ufo/ps/task.rb', line 13 def to_a row = [id, name, release, started, status, notes] row << container_instance_arn if extra_columns row end |