blob: 065d103fe07baa1e133c4814ac72aefca1fa5c5b (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# frozen_string_literal: true
module Projects
class RefreshBuildArtifactsSizeStatisticsWorker
include ApplicationWorker
include LimitedCapacity::Worker
data_consistency :always
feature_category :build_artifacts
idempotent!
MAX_RUNNING_LOW = 1
MAX_RUNNING_MEDIUM = 3
MAX_RUNNING_HIGH = 5
def perform_work(*args)
refresh = Projects::RefreshBuildArtifactsSizeStatisticsService.new.execute
return unless refresh
log_extra_metadata_on_done(:refresh_id, refresh.id)
log_extra_metadata_on_done(:project_id, refresh.project_id)
log_extra_metadata_on_done(:last_job_artifact_id, refresh.last_job_artifact_id)
log_extra_metadata_on_done(:last_batch, refresh.destroyed?)
log_extra_metadata_on_done(:refresh_started_at, refresh.refresh_started_at)
end
def remaining_work_count(*args)
# LimitedCapacity::Worker only needs to know if there is work left to do
# so we can get by with an EXISTS query rather than a count.
# https://gitlab.com/gitlab-org/gitlab/-/issues/356167
if Projects::BuildArtifactsSizeRefresh.remaining.any?
1
else
0
end
end
def max_running_jobs
if ::Feature.enabled?(:projects_build_artifacts_size_refresh_high, type: :ops)
MAX_RUNNING_HIGH
elsif ::Feature.enabled?(:projects_build_artifacts_size_refresh_medium, type: :ops)
MAX_RUNNING_MEDIUM
elsif ::Feature.enabled?(:projects_build_artifacts_size_refresh, type: :ops)
MAX_RUNNING_LOW
else
0
end
end
end
end
|