Class: Ufo::Ps::Task

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Task

Returns a new instance of Task.



7
8
9
# File 'lib/ufo/ps/task.rb', line 7

def initialize(task)
  @task = task
end

Class Method Details

.headerObject



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

def self.header
  %w[Id Name Release Started Status Notes]
end

Instance Method Details

#hide?Boolean

hide stopped tasks that are older than 10 minutes

Returns:

  • (Boolean)


43
44
45
# File 'lib/ufo/ps/task.rb', line 43

def hide?
  status == "STOPPED" && started_at < Time.now - 60 * 10
end

#idObject



15
16
17
# File 'lib/ufo/ps/task.rb', line 15

def id
  @task['task_arn'].split('/').last.split('-').first
end

#nameObject



19
20
21
22
23
# File 'lib/ufo/ps/task.rb', line 19

def name
  @task["overrides"]["container_overrides"].first["name"]
rescue NoMethodError
  @task["containers"].first["name"]
end

#notesObject



51
52
53
54
55
56
57
58
59
# File 'lib/ufo/ps/task.rb', line 51

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ufo/ps/task.rb', line 62

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

#releaseObject



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

def release
  @task["task_definition_arn"].split('/').last
end

#startedObject



29
30
31
32
33
34
# File 'lib/ufo/ps/task.rb', line 29

def started
  started = Time.parse(@task["started_at"].to_s)
  relative_time(started)
rescue ArgumentError
  "PENDING"
end

#started_atObject



36
37
38
39
40
# File 'lib/ufo/ps/task.rb', line 36

def started_at
  Time.parse(@task["started_at"].to_s)
rescue ArgumentError
  nil
end

#statusObject



47
48
49
# File 'lib/ufo/ps/task.rb', line 47

def status
  @task["last_status"]
end

#to_aObject



11
12
13
# File 'lib/ufo/ps/task.rb', line 11

def to_a
  [id, name, release, started, status, notes]
end