Class: StuckMergeJobsWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue
Defined in:
app/workers/stuck_merge_jobs_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Class Method Details

.loggerObject



12
13
14
# File 'app/workers/stuck_merge_jobs_worker.rb', line 12

def self.logger
  Gitlab::AppLogger
end

Instance Method Details

#performObject

rubocop: disable CodeReuse/ActiveRecord



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/stuck_merge_jobs_worker.rb', line 17

def perform
  stuck_merge_requests.find_in_batches(batch_size: 100) do |group|
    jids = group.map(&:merge_jid)

    # Find the jobs that aren't currently running or that exceeded the threshold.
    completed_jids = Gitlab::SidekiqStatus.completed_jids(jids)

    if completed_jids.any?
      completed_ids = group.select { |merge_request| completed_jids.include?(merge_request.merge_jid) }.map(&:id)

      apply_current_state!(completed_jids, completed_ids)
    end
  end
end