Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-14 12:30:06 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-17 20:47:03 +0300
commit22ef066862bffc443baf8a630b0752ce37dab01c (patch)
tree0997fe691ec6bdd003d63d76ce6deb79b258b67d /app/workers
parent11485c5acc9247e417838879a31af014972b999c (diff)
Avoid race condition when expiring artifacts
It may happen that job meant to remove expired artifacts will be executed asynchronously when, in the meantime, project associated with given build gets removed by another asynchronous job. In that case we should not remove artifacts because such build will be removed anyway, when project removal is complete.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/expire_build_instance_artifacts_worker.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/workers/expire_build_instance_artifacts_worker.rb b/app/workers/expire_build_instance_artifacts_worker.rb
index 916c2e633c1..d9e2cc37bb3 100644
--- a/app/workers/expire_build_instance_artifacts_worker.rb
+++ b/app/workers/expire_build_instance_artifacts_worker.rb
@@ -2,10 +2,14 @@ class ExpireBuildInstanceArtifactsWorker
include Sidekiq::Worker
def perform(build_id)
- build = Ci::Build.with_expired_artifacts.reorder(nil).find_by(id: build_id)
- return unless build
+ build = Ci::Build
+ .with_expired_artifacts
+ .reorder(nil)
+ .find_by(id: build_id)
- Rails.logger.info "Removing artifacts build #{build.id}..."
+ return unless build.try(:project)
+
+ Rails.logger.info "Removing artifacts for build #{build.id}..."
build.erase_artifacts!
end
end