Welcome to mirror list, hosted at ThFree Co, Russian Federation.

stuck_ci_builds_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca594e77e7cd844693b42d7b7c21c15fc6ed1741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class StuckCiBuildsWorker
  include Sidekiq::Worker

  BUILD_STUCK_TIMEOUT = 1.day

  def perform
    Rails.logger.info 'Cleaning stuck builds'

    builds = Ci::Build.running_or_pending.where('updated_at < ?', BUILD_STUCK_TIMEOUT.ago)
    builds.find_each(batch_size: 50).each do |build|
      Rails.logger.debug "Dropping stuck #{build.status} build #{build.id} for runner #{build.runner_id}"
      build.drop
    end

    # Update builds that failed to drop
    builds.update_all(status: 'failed')
  end
end