Class: Projects::RefreshBuildArtifactsSizeStatisticsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/projects/refresh_build_artifacts_size_statistics_service.rb

Constant Summary collapse

BATCH_SIZE =
500
REFRESH_INTERVAL_SECONDS =
0.1

Instance Method Summary collapse

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/projects/refresh_build_artifacts_size_statistics_service.rb', line 8

def execute
  refresh = Projects::BuildArtifactsSizeRefresh.process_next_refresh!

  return unless refresh&.running?

  batch = refresh.next_batch(limit: BATCH_SIZE).to_a

  if batch.any?
    increments = batch.map do |artifact|
      Gitlab::Counters::Increment.new(amount: artifact.size.to_i, ref: artifact.id)
    end

    Projects::BuildArtifactsSizeRefresh.transaction do
      # Mark the refresh ready for another worker to pick up and process the next batch
      refresh.requeue!(batch.last.id)

      ProjectStatistics.bulk_increment_statistic(refresh.project, :build_artifacts_size, increments)
    end

    sleep REFRESH_INTERVAL_SECONDS
  else
    refresh.schedule_finalize!
  end

  refresh
end