From 5437a0b09577ba2ed6f3f3b48e8a60aa37cfb4a8 Mon Sep 17 00:00:00 2001 From: Wedge Date: Fri, 24 May 2019 09:16:37 +0300 Subject: [PATCH] Move clearing stale builders to worker --- app/controllers/api/v1/jobs_controller.rb | 9 --------- app/jobs/build_lists/clear_stale_builders.rb | 10 ++++++++++ config/schedule.yml | 9 ++++++++- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 app/jobs/build_lists/clear_stale_builders.rb diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index 49ce6785d..13014c81e 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -8,7 +8,6 @@ class Api::V1::JobsController < Api::V1::BaseController skip_after_action :verify_authorized def shift - clear_stale_builders job_shift_sem = Redis::Semaphore.new(:job_shift_lock) job_shift_sem.lock uid = BuildList.scoped_to_arch(arch_ids). @@ -100,14 +99,6 @@ class Api::V1::JobsController < Api::V1::BaseController protected - def clear_stale_builders - BuildList.transaction do - BuildList.where(["updated_at < ?", 900.seconds.ago]).where(status: BuildList::BUILD_PENDING).where.not(builder: nil).find_each(batch_size: 50) do |bl| - bl.update_column(:builder_id, nil) - end - end - end - def platform_ids @platform_ids ||= begin platforms = params[:platforms].to_s.split(',') diff --git a/app/jobs/build_lists/clear_stale_builders.rb b/app/jobs/build_lists/clear_stale_builders.rb new file mode 100644 index 000000000..d14876236 --- /dev/null +++ b/app/jobs/build_lists/clear_stale_builders.rb @@ -0,0 +1,10 @@ +module BuildLists + class ClearStaleBuilders < BaseActiveRecordJob + include Sidekiq::Worker + sidekiq_options :queue => :low + + def perform_with_ar_connection + BuildList.where(["updated_at < ?", 900.seconds.ago]).where(status: BuildList::BUILD_PENDING).where.not(builder: nil).update_all(builder_id: nil) + end + end +end diff --git a/config/schedule.yml b/config/schedule.yml index 02fe53701..4d2ea1a79 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -68,4 +68,11 @@ build_canceling_destroy: - '1h' class: 'BuildLists::BuildCancelingDestroyJob' queue: low - description: 'Remove build canceling build lists' \ No newline at end of file + description: 'Remove build canceling build lists' + +clear_stale_builders: + every: + - '5m' + class: 'BuildLists::ClearStaleBuilders' + queue: low + description: 'Clear stale builders'