Class: MergeRequest::CleanupSchedule

Inherits:
ApplicationRecord show all
Defined in:
app/models/merge_request/cleanup_schedule.rb

Constant Summary collapse

STATUSES =
{
  unstarted: 0,
  running: 1,
  completed: 2,
  failed: 3
}.freeze
STUCK_RETRY_LIMIT =

NOTE: Limit the number of stuck schedule jobs to retry just in case it becomes too big.

5

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.start_nextObject



59
60
61
62
63
64
65
66
67
68
# File 'app/models/merge_request/cleanup_schedule.rb', line 59

def self.start_next
  MergeRequest::CleanupSchedule.transaction do
    cleanup_schedule = scheduled_and_unstarted.lock('FOR UPDATE SKIP LOCKED').first

    next if cleanup_schedule.blank?

    cleanup_schedule.run!
    cleanup_schedule
  end
end

.stuck_retry!Object



70
71
72
# File 'app/models/merge_request/cleanup_schedule.rb', line 70

def self.stuck_retry!
  self.stuck.limit(STUCK_RETRY_LIMIT).map(&:retry!)
end