BigW Consortium Gitlab

stuck_ci_builds_worker.rb 560 Bytes
Newer Older
1 2
class StuckCiBuildsWorker
  include Sidekiq::Worker
3
  include CronjobQueue
4 5 6 7 8 9

  BUILD_STUCK_TIMEOUT = 1.day

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

10
    builds = Ci::Build.joins(:project).running_or_pending.where('ci_builds.updated_at < ?', BUILD_STUCK_TIMEOUT.ago)
11 12 13 14
    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
15 16 17

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