diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /app/models/deployment.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'app/models/deployment.rb')
-rw-r--r-- | app/models/deployment.rb | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 3978620c74d..2d0d98136ec 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -46,6 +46,8 @@ class Deployment < ApplicationRecord scope :older_than, -> (deployment) { where('id < ?', deployment.id) } scope :with_deployable, -> { includes(:deployable).where('deployable_id IS NOT NULL') } + FINISHED_STATUSES = %i[success failed canceled].freeze + state_machine :status, initial: :created do event :run do transition created: :running @@ -63,27 +65,41 @@ class Deployment < ApplicationRecord transition any - [:canceled] => :canceled end - before_transition any => [:success, :failed, :canceled] do |deployment| + before_transition any => FINISHED_STATUSES do |deployment| deployment.finished_at = Time.current end - after_transition any => :success do |deployment| + after_transition any => :running do |deployment| + next unless deployment.project.ci_forward_deployment_enabled? + deployment.run_after_commit do - Deployments::SuccessWorker.perform_async(id) + Deployments::DropOlderDeploymentsWorker.perform_async(id) end end - after_transition any => [:success, :failed, :canceled] do |deployment| + after_transition any => :running do |deployment| deployment.run_after_commit do - Deployments::FinishedWorker.perform_async(id) + next unless Feature.enabled?(:ci_send_deployment_hook_when_start, deployment.project) + + Deployments::ExecuteHooksWorker.perform_async(id) end end - after_transition any => :running do |deployment| - next unless deployment.project.forward_deployment_enabled? + after_transition any => :success do |deployment| + deployment.run_after_commit do + Deployments::UpdateEnvironmentWorker.perform_async(id) + end + end + + after_transition any => FINISHED_STATUSES do |deployment| + deployment.run_after_commit do + Deployments::LinkMergeRequestWorker.perform_async(id) + end + end + after_transition any => FINISHED_STATUSES do |deployment| deployment.run_after_commit do - Deployments::ForwardDeploymentWorker.perform_async(id) + Deployments::ExecuteHooksWorker.perform_async(id) end end end @@ -273,7 +289,7 @@ class Deployment < ApplicationRecord SQL end - # Changes the status of a deployment and triggers the correspinding state + # Changes the status of a deployment and triggers the corresponding state # machine events. def update_status(status) case status |