Skip to content

Commit

Permalink
job_queue: add logging of long build queue
Browse files Browse the repository at this point in the history
This will make it easier to monitor whether the new queueing system is
behaving as expected.
  • Loading branch information
carlocab committed May 13, 2024
1 parent cc8d57b commit bdce7b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/job_queue.rb
Expand Up @@ -5,11 +5,12 @@

# A variation of `Thread::Queue` that allows us to prioritise certain types of jobs.
class JobQueue
def initialize(queue_type)
def initialize(queue_type, logger)
@mutex = Mutex.new
@queue = Hash.new { |h, k| h[k] = [] }
@queue_type = queue_type
@condvar = ConditionVariable.new
@logger = logger
end

def <<(job)
Expand All @@ -24,9 +25,12 @@ def pop
loop do
running_long_build_count = SharedState.instance.running_jobs(@queue_type).count(&:long_build?)
long_build_slots = QueueTypes.slots(@queue_type) / 2
@logger.call("Long builds: #{running_long_build_count} running, #{long_build_slots} available")

if running_long_build_count < long_build_slots && !@queue[:long].empty?
break @queue[:long].shift
job = @queue[:long].shift
@logger.call("Long build slot available. Scheduling #{job.runner_name} for deployment...")
break job
elsif !@queue[:default].empty?
break @queue[:default].shift
else
Expand Down
2 changes: 1 addition & 1 deletion src/orka_start_processor.rb
Expand Up @@ -27,7 +27,7 @@ class OrkaStartProcessor < ThreadRunner

def initialize(queue_type, name)
super("#{self.class.name} (#{name})")
@queue = JobQueue.new(queue_type)
@queue = JobQueue.new(queue_type, method(:log))
end

def pausable?
Expand Down

0 comments on commit bdce7b2

Please sign in to comment.