Move clearing stale builders to worker

This commit is contained in:
Wedge 2019-05-24 09:16:37 +03:00
parent d9f2a9f7fb
commit 5437a0b095
3 changed files with 18 additions and 10 deletions

View File

@ -8,7 +8,6 @@ class Api::V1::JobsController < Api::V1::BaseController
skip_after_action :verify_authorized skip_after_action :verify_authorized
def shift def shift
clear_stale_builders
job_shift_sem = Redis::Semaphore.new(:job_shift_lock) job_shift_sem = Redis::Semaphore.new(:job_shift_lock)
job_shift_sem.lock job_shift_sem.lock
uid = BuildList.scoped_to_arch(arch_ids). uid = BuildList.scoped_to_arch(arch_ids).
@ -100,14 +99,6 @@ class Api::V1::JobsController < Api::V1::BaseController
protected 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 def platform_ids
@platform_ids ||= begin @platform_ids ||= begin
platforms = params[:platforms].to_s.split(',') platforms = params[:platforms].to_s.split(',')

View File

@ -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

View File

@ -68,4 +68,11 @@ build_canceling_destroy:
- '1h' - '1h'
class: 'BuildLists::BuildCancelingDestroyJob' class: 'BuildLists::BuildCancelingDestroyJob'
queue: low queue: low
description: 'Remove build canceling build lists' description: 'Remove build canceling build lists'
clear_stale_builders:
every:
- '5m'
class: 'BuildLists::ClearStaleBuilders'
queue: low
description: 'Clear stale builders'