From a5a89176cf0cc961c42f89703483f4fa8dea0095 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sun, 12 May 2024 01:48:51 +0800 Subject: [PATCH] job_queue: avoid hard-coding limit for long-running jobs This allows us to keep track of the number of slots in one place instead of two. --- src/job_queue.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/job_queue.rb b/src/job_queue.rb index e647a39..4d776e9 100644 --- a/src/job_queue.rb +++ b/src/job_queue.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require_relative "queue_types" require_relative "shared_state" # A variation of `Thread::Queue` that allows us to prioritise certain types of jobs. @@ -22,8 +23,9 @@ def pop @mutex.synchronize do loop do running_long_build_count = SharedState.instance.running_jobs(@queue_type).count(&:long_build?) + long_build_slots = QueueTypes.slots(@queue_type) / 2 - if running_long_build_count < 6 && !@queue[:long].empty? + if running_long_build_count < long_build_slots && !@queue[:long].empty? break @queue[:long].shift elsif !@queue[:default].empty? break @queue[:default].shift