diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /app/services/ci/archive_trace_service.rb | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'app/services/ci/archive_trace_service.rb')
-rw-r--r-- | app/services/ci/archive_trace_service.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/services/ci/archive_trace_service.rb b/app/services/ci/archive_trace_service.rb index 3d548c824c8..4b62580e670 100644 --- a/app/services/ci/archive_trace_service.rb +++ b/app/services/ci/archive_trace_service.rb @@ -2,6 +2,36 @@ module Ci class ArchiveTraceService + include ::Gitlab::ExclusiveLeaseHelpers + + EXCLUSIVE_LOCK_KEY = 'archive_trace_service:batch_execute:lock' + LOCK_TIMEOUT = 56.minutes + LOOP_TIMEOUT = 55.minutes + LOOP_LIMIT = 2000 + BATCH_SIZE = 100 + + # rubocop: disable CodeReuse/ActiveRecord + def batch_execute(worker_name:) + start_time = Time.current + in_lock(EXCLUSIVE_LOCK_KEY, ttl: LOCK_TIMEOUT, retries: 1) do + Ci::Build.with_stale_live_trace.find_each(batch_size: BATCH_SIZE).with_index do |build, index| + break if Time.current - start_time > LOOP_TIMEOUT + + if index > LOOP_LIMIT + Sidekiq.logger.warn(class: worker_name, message: 'Loop limit reached.', job_id: build.id) + break + end + + begin + execute(build, worker_name: worker_name) + rescue StandardError + next + end + end + end + end + # rubocop: enable CodeReuse/ActiveRecord + def execute(job, worker_name:) unless job.trace.archival_attempts_available? Sidekiq.logger.warn(class: worker_name, message: 'The job is out of archival attempts.', job_id: job.id) |