Skip to content

Commit

Permalink
Merge pull request #261 from Shopify/cbruckmayer/consider-total-time
Browse files Browse the repository at this point in the history
Consider waiting for master in total duration
  • Loading branch information
ChrisBr authored Mar 25, 2024
2 parents cfb741e + 9739e1d commit 02357c4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ruby/lib/ci/queue/redis/supervisor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module CI
module Queue
module Redis
Expand All @@ -17,11 +18,13 @@ def build
end

def wait_for_workers
wait_for_master(timeout: config.queue_init_timeout)
duration = measure do
wait_for_master(timeout: config.queue_init_timeout)
end

yield if block_given?

time_left = config.report_timeout
time_left = config.report_timeout - duration.to_i
time_left_with_no_workers = config.inactive_workers_timeout
until exhausted? || time_left <= 0 || max_test_failed? || time_left_with_no_workers <= 0
time_left -= 1
Expand All @@ -44,6 +47,12 @@ def wait_for_workers

private

def measure
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting
end

def active_workers?
# if there are running jobs we assume there are still agents active
redis.zrangebyscore(key('running'), CI::Queue.time_now.to_f - config.timeout, "+inf", limit: [0,1]).count > 0
Expand Down

0 comments on commit 02357c4

Please sign in to comment.