class Ufo::Stop
Public Instance Methods
latest_deployed_arn()
click to toggle source
latest deployment task definition arn
# File lib/ufo/stop.rb, line 27 def latest_deployed_arn latest = @deployments.sort_by do |deployment| Time.parse(deployment["created_at"].to_s) end.last latest["task_definition"] end
log(text)
click to toggle source
# File lib/ufo/stop.rb, line 40 def log(text) path = "#{Ufo.root}/.ufo/log/stop.log" FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'a') do |f| f.puts("#{Time.now} #{text}") end puts text unless @options[:mute] end
run()
click to toggle source
# File lib/ufo/stop.rb, line 3 def run info = Info.new(@service, @options) service = info.service return unless service # brand new deploy @deployments = service.deployments if @deployments.size > 1 stop_old_tasks(service.service_name) end end
service_tasks(cluster, service_name)
click to toggle source
# File lib/ufo/stop.rb, line 34 def service_tasks(cluster, 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
stop_old_tasks(service_name)
click to toggle source
# File lib/ufo/stop.rb, line 14 def stop_old_tasks(service_name) # json = JSON.pretty_generate(deployments.map(&:to_h)) # IO.write("/tmp/deployments.json", json) tasks = service_tasks(@cluster, service_name) reason = "Ufo #{Ufo::VERSION} has deployed new code and stopping old tasks." tasks.each do |task| next if task["task_definition_arn"] == latest_deployed_arn log "Stopping task #{task["task_arn"]}" ecs.stop_task(cluster: @cluster, task: task["task_arn"], reason: reason) end end