summaryrefslogtreecommitdiff
path: root/app/workers/expire_build_artifacts_worker.rb
blob: 6f0e0fd33f7204e1040503054a713984e3aa8567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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' # rubocop:disable Gitlab/RailsLogger

    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