diff options
Diffstat (limited to 'app/workers/stuck_ci_builds_worker.rb')
-rw-r--r-- | app/workers/stuck_ci_builds_worker.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/workers/stuck_ci_builds_worker.rb b/app/workers/stuck_ci_builds_worker.rb new file mode 100644 index 00000000000..ca594e77e7c --- /dev/null +++ b/app/workers/stuck_ci_builds_worker.rb @@ -0,0 +1,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 |