diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-03 06:09:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-03 06:09:20 +0300 |
commit | 531a68a424fddcc936ba6271fbb10a5aa1da75a7 (patch) | |
tree | 6c4484fede42157f3d1187825d824988a971d0ca /app/models/merge_request | |
parent | 94aee277313c742f9b54b329fd4043cde7a50915 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/merge_request')
-rw-r--r-- | app/models/merge_request/cleanup_schedule.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/merge_request/cleanup_schedule.rb b/app/models/merge_request/cleanup_schedule.rb index 35194b2b318..7f52a110da1 100644 --- a/app/models/merge_request/cleanup_schedule.rb +++ b/app/models/merge_request/cleanup_schedule.rb @@ -8,6 +8,9 @@ class MergeRequest::CleanupSchedule < ApplicationRecord failed: 3 }.freeze + # NOTE: Limit the number of stuck schedule jobs to retry just in case it becomes too big. + STUCK_RETRY_LIMIT = 5 + belongs_to :merge_request, inverse_of: :cleanup_schedule validates :scheduled_at, presence: true @@ -48,6 +51,11 @@ class MergeRequest::CleanupSchedule < ApplicationRecord .order('scheduled_at DESC') } + # NOTE: It is considered stuck as it is unusual to take more than 6 hours to finish the cleanup task. + scope :stuck, -> { + where('updated_at <= NOW() - interval \'6 hours\' AND status = ?', STATUSES[:running]) + } + def self.start_next MergeRequest::CleanupSchedule.transaction do cleanup_schedule = scheduled_and_unstarted.lock('FOR UPDATE SKIP LOCKED').first @@ -58,4 +66,8 @@ class MergeRequest::CleanupSchedule < ApplicationRecord cleanup_schedule end end + + def self.stuck_retry! + self.stuck.limit(STUCK_RETRY_LIMIT).map(&:retry!) + end end |