Class: Ci::DestroyExpiredJobArtifactsService

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

Constant Summary collapse

BATCH_SIZE =
100
LOOP_TIMEOUT =
45.minutes
LOOP_LIMIT =
1000
EXCLUSIVE_LOCK_KEY =
'expired_job_artifacts:destroy:lock'
LOCK_TIMEOUT =
50.minutes

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

Instance Method Details

#executeObject

Destroy expired job artifacts on GitLab instance

This destroy process cannot run for more than 45 minutes. This is for preventing multiple `ExpireBuildArtifactsWorker` CRON jobs run concurrently, which is scheduled at every hour.


20
21
22
23
24
25
26
# File 'app/services/ci/destroy_expired_job_artifacts_service.rb', line 20

def execute
  in_lock(EXCLUSIVE_LOCK_KEY, ttl: LOCK_TIMEOUT, retries: 1) do
    loop_until(timeout: LOOP_TIMEOUT, limit: LOOP_LIMIT) do
      destroy_batch(Ci::JobArtifact) || destroy_batch(Ci::PipelineArtifact)
    end
  end
end