Class: Ufo::CLI::Ps::Task
- Inherits:
-
Base
- Object
- Base
- Ufo::CLI::Ps::Task
show all
- Defined in:
- lib/ufo/cli/ps/task.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#sure?
#pretty_home, #pretty_path, #pretty_time
#logger
#build, #deploy, #info, #ps
#names
#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client
#find_stack, #find_stack_resources, #stack_resources, #task_definition_arns
Constructor Details
#initialize(options = {}) ⇒ Task
Returns a new instance of Task.
3
4
5
6
|
# File 'lib/ufo/cli/ps/task.rb', line 3
def initialize(options={})
super
@task = options[:task] end
|
Class Method Details
122
123
124
|
# File 'lib/ufo/cli/ps/task.rb', line 122
def
%w[Task Name Release Started Status Notes]
end
|
Instance Method Details
#container_instance_arn ⇒ Object
50
51
52
|
# File 'lib/ufo/cli/ps/task.rb', line 50
def container_instance_arn
@task['container_instance_arn'].split('/').last
end
|
#container_names ⇒ Object
PENDING wont yet have any containers yet but since using task definition we’re ok
30
31
32
33
34
35
36
|
# File 'lib/ufo/cli/ps/task.rb', line 30
def container_names
task_definition = task_definition(@task.task_definition_arn)
names = task_definition.container_definitions.map do |container_definition|
container_definition.name
end
names.join(',')
end
|
#hide? ⇒ Boolean
hide stopped tasks have been stopped for more than 5 minutes
created_at=2018-07-05 21:52:13 -0700,
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,
75
76
77
78
79
80
81
82
83
|
# File 'lib/ufo/cli/ps/task.rb', line 75
def hide?
return false if @options[:status] == "stopped"
stopped_at = time(@task["stopped_at"])
return false unless stopped_at
time = Time.now - 60 * Ufo.config.ps.hide_age
status == "STOPPED" && stopped_at < time
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/ufo/cli/ps/task.rb', line 13
def id
@task['task_arn'].split('/').last.split('-').first
end
|
#name ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ufo/cli/ps/task.rb', line 17
def name
container_overrides = @task.dig("overrides", "container_overrides")
overrides = container_overrides if !overrides.empty? overrides.map { |i| i["name"] }.join(',')
else
container_names
end
rescue NoMethodError
container_names
end
|
#notes ⇒ Object
Grab all the reasons and surface to user. Even though will make the table output ugly, debugging info merits it.
ufo ps --format json
94
95
96
97
98
99
100
101
102
|
# File 'lib/ufo/cli/ps/task.rb', line 94
def notes
return unless @task["stopped_reason"]
notes = []
notes << "Task Stopped Reason: #{@task["stopped_reason"]}."
@task.containers.each do |container|
notes << "Container #{container.name} reason: #{container.reason}" unless container.reason.blank?
end
notes.join(" ")
end
|
#relative_time(start_time) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/ufo/cli/ps/task.rb', line 105
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
54
55
56
|
# File 'lib/ufo/cli/ps/task.rb', line 54
def release
@task["task_definition_arn"].split('/').last
end
|
#started ⇒ Object
58
59
60
61
62
|
# File 'lib/ufo/cli/ps/task.rb', line 58
def started
started = time(@task["started_at"])
return "PENDING" unless started
relative_time(started)
end
|
#status ⇒ Object
85
86
87
|
# File 'lib/ufo/cli/ps/task.rb', line 85
def status
@task["last_status"]
end
|
#task_definition(task_definition_arn) ⇒ Object
ECS inconsistently returns the container names in random order Look up the names from the task definition to try and get right order This still seems to return inconsistently. IE: Not the order that was defined in the task definition originally
42
43
44
45
46
47
|
# File 'lib/ufo/cli/ps/task.rb', line 42
def task_definition(task_definition_arn)
resp = ecs.describe_task_definition(
task_definition: task_definition_arn,
)
resp.task_definition
end
|
#time(value) ⇒ Object
64
65
66
67
68
|
# File 'lib/ufo/cli/ps/task.rb', line 64
def time(value)
Time.parse(value.to_s)
rescue ArgumentError
nil
end
|
#to_a ⇒ Object
8
9
10
11
|
# File 'lib/ufo/cli/ps/task.rb', line 8
def to_a
row = [id, name, release, started, status, notes]
row
end
|