Class: Ufo::CLI::Stop
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#latest_deployed_arn ⇒ Object
latest deployment task definition arn.
- #run ⇒ Object
- #service_tasks(service_name) ⇒ Object
- #show(tasks, preview: true) ⇒ Object
- #stop(service_name) ⇒ Object
Methods inherited from Base
Methods included from Utils::Sure
Methods included from Utils::Pretty
#pretty_home, #pretty_path, #pretty_time
Methods included from Utils::Logging
Methods included from Ufo::Concerns
Methods included from Ufo::Concerns::Names
Methods included from AwsServices
#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client
Methods included from AwsServices::Concerns
#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns
Constructor Details
This class inherits a constructor from Ufo::CLI::Base
Instance Method Details
#latest_deployed_arn ⇒ Object
latest deployment task definition arn
36 37 38 39 40 41 |
# File 'lib/ufo/cli/stop.rb', line 36 def latest_deployed_arn latest = @deployments.sort_by do |deployment| Time.parse(deployment["created_at"].to_s) end.last latest["task_definition"] end |
#run ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/ufo/cli/stop.rb', line 3 def run service = info.service return unless service # brand new deploy @deployments = service.deployments if @deployments.size >= 1 stop(service.service_name) end end |
#service_tasks(service_name) ⇒ Object
43 44 45 46 47 |
# File 'lib/ufo/cli/stop.rb', line 43 def service_tasks(service_name) all_task_arns = ecs.list_tasks(cluster: @cluster, service_name: service_name).task_arns return [] if all_task_arns.empty? ecs.describe_tasks(cluster: @cluster, tasks: all_task_arns).tasks end |
#show(tasks, preview: true) ⇒ Object
29 30 31 32 33 |
# File 'lib/ufo/cli/stop.rb', line 29 def show(tasks, preview: true) logger.info "Will stop the following tasks:" if preview ps = Ps.new(@options) ps.show_tasks(tasks) end |
#stop(service_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ufo/cli/stop.rb', line 13 def stop(service_name) tasks = service_tasks(service_name) show(tasks, preview: true) unless @options[:yes] sure? tasks.each do |task| if @options[:stop_old_tasks] next if task["task_definition_arn"] == latest_deployed_arn end logger.debug "stop task #{task["task_arn"]}" meth = "stop_task" ecs.stop_task(cluster: @cluster, task: task["task_arn"], reason: "stop by ufo") end logger.info "Stopping tasks" show(tasks, preview: false) if @options[:yes] end |