Class: Ci::JobArtifacts::DestroyAssociationsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/job_artifacts/destroy_associations_service.rb

Constant Summary collapse

BATCH_SIZE =
100

Instance Method Summary collapse

Constructor Details

#initialize(job_artifacts_relation) ⇒ DestroyAssociationsService

Returns a new instance of DestroyAssociationsService.


8
9
10
11
# File 'app/services/ci/job_artifacts/destroy_associations_service.rb', line 8

def initialize(job_artifacts_relation)
  @job_artifacts_relation = job_artifacts_relation
  @statistics = {}
end

Instance Method Details

#destroy_recordsObject


13
14
15
16
17
18
19
20
21
# File 'app/services/ci/job_artifacts/destroy_associations_service.rb', line 13

def destroy_records
  @job_artifacts_relation.each_batch(of: BATCH_SIZE) do |relation|
    service = Ci::JobArtifacts::DestroyBatchService.new(relation, pick_up_at: Time.current, fix_expire_at: false)
    result  = service.execute(update_stats: false)
    updates = result[:statistics_updates]

    @statistics.merge!(updates) { |_key, oldval, newval| newval + oldval }
  end
end

#update_statisticsObject


23
24
25
26
27
# File 'app/services/ci/job_artifacts/destroy_associations_service.rb', line 23

def update_statistics
  @statistics.each do |project, delta|
    project.increment_statistic_value(Ci::JobArtifact.project_statistics_name, delta)
  end
end