diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-07 20:58:36 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-07 20:58:36 +0300 |
commit | c901936a829885263a602431e5762b0352073a2a (patch) | |
tree | 55378fc75cecd3b7503b3b60f0a78e0dcc4ca90f /app | |
parent | 2cd8b5d2c0227f21020a81b9931ca6936e833727 (diff) | |
parent | 9afb2dac5c9f49f9f7943053b50a3808a99fdf6b (diff) |
Merge branch '23096-expire-artifacts-per-job' into 'master'
ExpireBuildArtifactsWorker query builds table without ordering enqueuing one job…
See merge request !6732
Diffstat (limited to 'app')
-rw-r--r-- | app/workers/expire_build_artifacts_worker.rb | 11 | ||||
-rw-r--r-- | app/workers/expire_build_instance_artifacts_worker.rb | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/app/workers/expire_build_artifacts_worker.rb b/app/workers/expire_build_artifacts_worker.rb index c64ea108d52..174eabff9fd 100644 --- a/app/workers/expire_build_artifacts_worker.rb +++ b/app/workers/expire_build_artifacts_worker.rb @@ -2,12 +2,11 @@ class ExpireBuildArtifactsWorker include Sidekiq::Worker def perform - Rails.logger.info 'Cleaning old build artifacts' + Rails.logger.info 'Scheduling removal of build artifacts' - builds = Ci::Build.with_expired_artifacts - builds.find_each(batch_size: 50).each do |build| - Rails.logger.debug "Removing artifacts build #{build.id}..." - build.erase_artifacts! - end + build_ids = Ci::Build.with_expired_artifacts.pluck(:id) + build_ids = build_ids.map { |build_id| [build_id] } + + Sidekiq::Client.push_bulk('class' => ExpireBuildInstanceArtifactsWorker, 'args' => build_ids ) end end diff --git a/app/workers/expire_build_instance_artifacts_worker.rb b/app/workers/expire_build_instance_artifacts_worker.rb new file mode 100644 index 00000000000..916c2e633c1 --- /dev/null +++ b/app/workers/expire_build_instance_artifacts_worker.rb @@ -0,0 +1,11 @@ +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 + + Rails.logger.info "Removing artifacts build #{build.id}..." + build.erase_artifacts! + end +end |