Sha256: 0e6cbab3b88fdbb0ae6d36b7fb5fd620aad66693cde35d5755728c2e34c383b8

Contents?: true

Size: 1.42 KB

Versions: 34

Compression:

Stored size: 1.42 KB

Contents

class Ufo::CLI
  class Stop < Base
    def run
      service = info.service
      return unless service # brand new deploy

      @deployments = service.deployments
      if @deployments.size >= 1
        stop(service.service_name)
      end
    end

    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

    def show(tasks, preview: true)
      logger.info "Will stop the following tasks:" if preview
      ps = Ps.new(@options)
      ps.show_tasks(tasks)
    end

    # latest deployment task definition arn
    def latest_deployed_arn
      latest = @deployments.sort_by do |deployment|
        Time.parse(deployment["created_at"].to_s)
      end.last
      latest["task_definition"]
    end

    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
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ufo-6.3.13 lib/ufo/cli/stop.rb
ufo-6.3.12 lib/ufo/cli/stop.rb
ufo-6.3.11 lib/ufo/cli/stop.rb
ufo-6.3.10 lib/ufo/cli/stop.rb
ufo-6.3.9 lib/ufo/cli/stop.rb
ufo-6.3.8 lib/ufo/cli/stop.rb
ufo-6.3.7 lib/ufo/cli/stop.rb
ufo-6.3.6 lib/ufo/cli/stop.rb
ufo-6.3.5 lib/ufo/cli/stop.rb
ufo-6.3.4 lib/ufo/cli/stop.rb
ufo-6.3.3 lib/ufo/cli/stop.rb
ufo-6.3.2 lib/ufo/cli/stop.rb
ufo-6.3.1 lib/ufo/cli/stop.rb
ufo-6.3.0 lib/ufo/cli/stop.rb
ufo-6.2.5 lib/ufo/cli/stop.rb
ufo-6.2.4 lib/ufo/cli/stop.rb
ufo-6.2.3 lib/ufo/cli/stop.rb
ufo-6.2.2 lib/ufo/cli/stop.rb
ufo-6.2.1 lib/ufo/cli/stop.rb
ufo-6.2.0 lib/ufo/cli/stop.rb