gitlab-org--gitlab-foss/app/workers/expire_build_artifacts_worker.rb
Shinya Maeda 3cc3650dfe Remove expired artifacts periodically
Rename

Introduce Destroy expired job artifacts service

Revert a bit

Add changelog

Use expired

Improve

Fix spec

Fix spec

Use bang for destroy

Introduce iteration limit

Update comment

Simplify more

Refacor

Remove unnecessary thing

Fix comments

Fix coding offence

Make loop helper exception free
2019-01-24 20:50:42 +09:00

29 lines
808 B
Ruby

# frozen_string_literal: true
class ExpireBuildArtifactsWorker
include ApplicationWorker
include CronjobQueue
def perform
if Feature.enabled?(:ci_new_expire_job_artifacts_service, default_enabled: true)
perform_efficient_artifacts_removal
else
perform_legacy_artifacts_removal
end
end
def perform_efficient_artifacts_removal
Ci::DestroyExpiredJobArtifactsService.new.execute
end
# rubocop: disable CodeReuse/ActiveRecord
def perform_legacy_artifacts_removal
Rails.logger.info 'Scheduling removal of build artifacts'
build_ids = Ci::Build.with_expired_artifacts.pluck(:id)
build_ids = build_ids.map { |build_id| [build_id] }
ExpireBuildInstanceArtifactsWorker.bulk_perform_async(build_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
end