summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-10-30 14:53:24 +0900
committerShinya Maeda <shinya@gitlab.com>2018-10-30 14:53:24 +0900
commit05f1f9eda73e17c0e1f40d3e926ed1ea57bccb56 (patch)
tree4838db4416c05006bae3e4216f2cbb531dfbe830
parent6491b4e0d4b83dfe3323ddb837f5e0559bef3dbf (diff)
downloadgitlab-ce-refactor-has-many-deployments.tar.gz
Fix last_deployment in Ci::Buildrefactor-has-many-deployments
-rw-r--r--app/models/ci/build.rb19
-rw-r--r--app/workers/build_success_worker.rb2
2 files changed, 9 insertions, 12 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 82778db5d71..72eee0ce5c8 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -16,14 +16,11 @@ module Ci
belongs_to :trigger_request
belongs_to :erased_by, class_name: 'User'
- has_many :deployments, -> { success }, as: :deployable
-
RUNNER_FEATURES = {
upload_multiple_artifacts: -> (build) { build.publishes_artifacts_reports? }
}.freeze
- has_one :last_deployment, -> { success.order('deployments.id DESC') }, as: :deployable, class_name: 'Deployment'
- has_one :real_last_deployment, -> { order('deployments.id DESC') }, as: :deployable, class_name: 'Deployment'
+ has_one :deployment, as: :deployable, class_name: 'Deployment'
has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id
@@ -197,7 +194,7 @@ module Ci
end
after_transition pending: :running do |build|
- build.real_last_deployment&.run
+ build.deployment&.run
build.run_after_commit do
BuildHooksWorker.perform_async(id)
@@ -211,7 +208,7 @@ module Ci
end
after_transition any => [:success] do |build|
- build.real_last_deployment&.succeed
+ build.deployment&.succeed
build.run_after_commit do
PagesWorker.perform_async(:deploy, id) if build.pages_generator?
@@ -221,7 +218,7 @@ module Ci
before_transition any => [:failed] do |build|
next unless build.project
- build.real_last_deployment&.drop
+ build.deployment&.drop
next if build.retries_max.zero?
@@ -243,7 +240,7 @@ module Ci
end
after_transition any => [:skipped, :canceled] do |build|
- build.real_last_deployment&.cancel
+ build.deployment&.cancel
end
end
@@ -336,7 +333,7 @@ module Ci
end
def outdated_deployment?
- success? && !last_deployment.try(:last?)
+ success? && !deployment.try(:last?)
end
def depends_on_builds
@@ -739,9 +736,9 @@ module Ci
end
def successful_deployment_status
- if success? && last_deployment&.last?
+ if success? && deployment&.last?
return :last
- elsif success? && last_deployment.present?
+ elsif success? && deployment.present?
return :out_of_date
end
diff --git a/app/workers/build_success_worker.rb b/app/workers/build_success_worker.rb
index 5e240460dfe..9c6fdaa7c6f 100644
--- a/app/workers/build_success_worker.rb
+++ b/app/workers/build_success_worker.rb
@@ -9,7 +9,7 @@ class BuildSuccessWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
- break if build.real_last_deployment
+ break if build.deployment
create_deployment(build) if build.has_environment?
end