diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-24 15:07:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-24 15:07:34 +0000 |
commit | df9890e9a702e2f12bbc8f022b916ca72820a292 (patch) | |
tree | 26ff255cfb6843fe963fcafea9ee70121ee5e913 /app/services/ci/runners | |
parent | 17c1c66eefd05243dd8ed2c8fd49d17ab1a52522 (diff) | |
download | gitlab-ce-df9890e9a702e2f12bbc8f022b916ca72820a292.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/ci/runners')
-rw-r--r-- | app/services/ci/runners/stale_machines_cleanup_service.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/services/ci/runners/stale_machines_cleanup_service.rb b/app/services/ci/runners/stale_machines_cleanup_service.rb new file mode 100644 index 00000000000..3e5706d24a6 --- /dev/null +++ b/app/services/ci/runners/stale_machines_cleanup_service.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Ci + module Runners + class StaleMachinesCleanupService + MAX_DELETIONS = 1000 + + def execute + ServiceResponse.success(payload: { + # the `stale` relationship can return duplicates, so we don't try to return a precise count here + deleted_machines: delete_stale_runner_machines > 0 + }) + end + + private + + def delete_stale_runner_machines + total_deleted_count = 0 + loop do + sub_batch_limit = [100, MAX_DELETIONS].min + + # delete_all discards part of the `stale` scope query, so we expliclitly wrap it with a SELECT as a workaround + deleted_count = Ci::RunnerMachine.id_in(Ci::RunnerMachine.stale.limit(sub_batch_limit)).delete_all + total_deleted_count += deleted_count + + break if deleted_count == 0 || total_deleted_count >= MAX_DELETIONS + end + + total_deleted_count + end + end + end +end |