diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/services/merge_requests/cleanup_refs_service.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/services/merge_requests/cleanup_refs_service.rb')
-rw-r--r-- | app/services/merge_requests/cleanup_refs_service.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/app/services/merge_requests/cleanup_refs_service.rb b/app/services/merge_requests/cleanup_refs_service.rb index d003124a112..23ac8e393f4 100644 --- a/app/services/merge_requests/cleanup_refs_service.rb +++ b/app/services/merge_requests/cleanup_refs_service.rb @@ -9,7 +9,7 @@ module MergeRequests attr_reader :merge_request def self.schedule(merge_request) - MergeRequestCleanupRefsWorker.perform_in(TIME_THRESHOLD, merge_request.id) + merge_request.create_cleanup_schedule(scheduled_at: TIME_THRESHOLD.from_now) end def initialize(merge_request) @@ -22,6 +22,7 @@ module MergeRequests end def execute + return error("Merge request is not scheduled to be cleaned up yet.") unless scheduled? return error("Merge request has not been closed nor merged for #{TIME_THRESHOLD.inspect}.") unless eligible? # Ensure that commit shas of refs are kept around so we won't lose them when GC runs. @@ -30,7 +31,10 @@ module MergeRequests return error('Failed to create keep around refs.') unless kept_around? return error('Failed to cache merge ref sha.') unless cache_merge_ref_sha - delete_refs + delete_refs if repository.exists? + + return error('Failed to update schedule.') unless update_schedule + success end @@ -38,6 +42,10 @@ module MergeRequests attr_reader :repository, :ref_path, :merge_ref_path, :ref_head_sha, :merge_ref_sha + def scheduled? + merge_request.cleanup_schedule.present? && merge_request.cleanup_schedule.scheduled_at <= Time.current + end + def eligible? return met_time_threshold?(merge_request.metrics&.latest_closed_at) if merge_request.closed? @@ -71,5 +79,9 @@ module MergeRequests def delete_refs repository.delete_refs(ref_path, merge_ref_path) end + + def update_schedule + merge_request.cleanup_schedule.update(completed_at: Time.current) + end end end |