2015-10-21 05:29:47 -04:00
|
|
|
class StuckCiBuildsWorker
|
|
|
|
include Sidekiq::Worker
|
2016-10-21 12:13:41 -04:00
|
|
|
include CronjobQueue
|
2015-10-21 05:29:47 -04:00
|
|
|
|
|
|
|
BUILD_STUCK_TIMEOUT = 1.day
|
|
|
|
|
|
|
|
def perform
|
|
|
|
Rails.logger.info 'Cleaning stuck builds'
|
|
|
|
|
2016-06-12 09:15:58 -04:00
|
|
|
builds = Ci::Build.joins(:project).running_or_pending.where('ci_builds.updated_at < ?', BUILD_STUCK_TIMEOUT.ago)
|
2015-10-21 05:29:47 -04:00
|
|
|
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
|
2015-11-23 07:49:40 -05:00
|
|
|
|
|
|
|
# Update builds that failed to drop
|
|
|
|
builds.update_all(status: 'failed')
|
2015-10-21 05:29:47 -04:00
|
|
|
end
|
|
|
|
end
|