blob: 7b6590a117c4aad34a4e404eb77ab3fad157128f (
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 Ci
module PipelineArtifacts
class DestroyAllExpiredService
include ::Gitlab::LoopHelpers
include ::Gitlab::Utils::StrongMemoize
BATCH_SIZE = 100
LOOP_TIMEOUT = 5.minutes
LOOP_LIMIT = 1000
def initialize
@removed_artifacts_count = 0
end
def execute
loop_until(timeout: LOOP_TIMEOUT, limit: LOOP_LIMIT) do
destroy_artifacts_batch
end
@removed_artifacts_count
end
private
def destroy_artifacts_batch
artifacts = ::Ci::PipelineArtifact.unlocked.expired(BATCH_SIZE).to_a
return false if artifacts.empty?
artifacts.each(&:destroy!)
increment_stats(artifacts.size)
true
end
def increment_stats(size)
destroyed_artifacts_counter.increment({}, size)
@removed_artifacts_count += size
end
def destroyed_artifacts_counter
strong_memoize(:destroyed_artifacts_counter) do
name = :destroyed_pipeline_artifacts_count_total
comment = 'Counter of destroyed expired pipeline artifacts'
::Gitlab::Metrics.counter(name, comment)
end
end
end
end
end
|