Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle service CF stack failure #315

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/deploy_runner_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def perform(heritage, without_before_deploy:, description: "")

def other_deploy_in_progress?(heritage)
return false if heritage.version == 1
heritage.services.map { |s| !s.deployment_finished?(nil) }.any?
heritage.services.map { |s| s.deployment_status(nil) == :in_progress }.any?
end
end
7 changes: 5 additions & 2 deletions app/jobs/monitor_deployment_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ class MonitorDeploymentJob < ActiveJob::Base
queue_as :default

def perform(service, count: 0, deployment_id: nil)
if service.deployment_finished?(deployment_id)
service.heritage.events.create!(level: :good, message: "#{service.name} service deployed")
status = service.deployment_status
if status == :complete
service.heritage.events.create!(level: :good, message: "#{service.name} service has been deployed")
elsif status == :failed
service.heritage.events.create!(level: :error, message: "#{service.name} service deployment failed")
elsif count > 200
# deploys not finished after 1000 seconds are marked as timeout
service.heritage.events.create!(level: :error, message: "Deploying #{service.name} service has not finished for a while.")
Expand Down
12 changes: 7 additions & 5 deletions app/models/backend/ecs/v1/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,22 @@ def endpoint
end
end

def deployment_finished?(deployment_id)
def deployment_status(deployment_id)
deployment = ecs_service.deployment(deployment_id)
# deployment being nil means the deployment finished and
# another newer deployment takes in place as PRIMARY
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Deployment.html
return true if deployment.nil? || deployment.status == "INACTIVE"
return :complete if deployment.nil? || deployment.status == "INACTIVE"

# A deployment is considered as finished when
# 1) There is only one PRIMARY deployment, and
# 2) The number of running tasks deployed by PRIMARY deployment
# reaches to service's desired task count
ecs_service.deployments.count == 1 &&
deployment.status == "PRIMARY" &&
deployment.desired_count == deployment.running_count
if ecs_service.deployments.count == 1 && deployment.status == "PRIMARY" && deployment.desired_count == deployment.running_count
:complete
else
:in_progress
end
end

def ecs_service
Expand Down
14 changes: 12 additions & 2 deletions app/models/backend/ecs/v2/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ def endpoint
nil
end

def deployment_finished?(_)
!cf_executor.in_progress?
def deployment_status(_)
status = cf_executor.stack_status
case status
when "CREATE_COMPLETE", "UPDATE_COMPLETE"
:complete
when "CREATE_FAILED", /^ROLLBACK_/, /^UPDATE_ROLLBACK_/
# regardless of a specific rollback status,
# if rollback has happened barcelona handles it as "failed"
:failed
when "CREATE_IN_PROGRESS", "UPDATE_IN_PROGRESS"
:in_progress
end
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def https_port_mapping
port_mappings.find_by(protocol: 'https')
end

def deployment_finished?(deployment_id)
backend.deployment_finished?(deployment_id)
def deployment_status(deployment_id)
backend.deployment_status(deployment_id)
end

private
Expand Down