Class: Ci::JobArtifacts::DestroyAllExpiredService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::ExclusiveLeaseHelpers, Gitlab::LoopHelpers
Defined in:
app/services/ci/job_artifacts/destroy_all_expired_service.rb

Constant Summary collapse

BATCH_SIZE =
100
LOOP_LIMIT =
500
LOOP_TIMEOUT =
5.minutes
LOCK_TIMEOUT =
6.minutes
EXCLUSIVE_LOCK_KEY =
'expired_job_artifacts:destroy:lock'

Constants included from Gitlab::ExclusiveLeaseHelpers

Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError

Instance Method Summary collapse

Methods included from Gitlab::LoopHelpers

#loop_until

Methods included from Gitlab::ExclusiveLeaseHelpers

#in_lock

Constructor Details

#initializeDestroyAllExpiredService

Returns a new instance of DestroyAllExpiredService.



15
16
17
18
# File 'app/services/ci/job_artifacts/destroy_all_expired_service.rb', line 15

def initialize
  @removed_artifacts_count = 0
  @start_at = Time.current
end

Instance Method Details

#executeObject

Destroy expired job artifacts on GitLab instance

This destroy process cannot run for more than 6 minutes. This is for preventing multiple ‘ExpireBuildArtifactsWorker` CRON jobs run concurrently, which is scheduled every 7 minutes.



26
27
28
29
30
31
32
# File 'app/services/ci/job_artifacts/destroy_all_expired_service.rb', line 26

def execute
  in_lock(EXCLUSIVE_LOCK_KEY, ttl: LOCK_TIMEOUT, retries: 1) do
    destroy_unlocked_job_artifacts
  end

  @removed_artifacts_count
end