Skip to content

Commit e327005

Browse files
committed
Dump the queue state from idle workers
1 parent 9c7bbbf commit e327005

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

ruby/lib/ci/queue/redis/worker.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
require 'active_support/time'
23
require 'ci/queue/static'
34
require 'set'
45

@@ -50,10 +51,22 @@ def master?
5051

5152
def poll
5253
wait_for_master
54+
idle_since = nil
55+
idle_state_printed = false
5356
until shutdown_required? || config.circuit_breakers.any?(&:open?) || exhausted? || max_test_failed?
5457
if test = reserve
58+
idle_since = nil
5559
yield index.fetch(test)
5660
else
61+
idle_since ||= Time.zone.now
62+
if Time.zone.now - idle_since > 0 && !idle_state_printed
63+
puts "Worker #{worker_id} has been idle for 120 seconds. Printing global state..."
64+
puts " Processed tests: #{redis.scard(key('processed'))}"
65+
puts " Pending tests: #{redis.llen(key('queue'))}. #{redis.lrange(key('queue'), 0, -1)}"
66+
puts " Running tests: #{redis.zcard(key('running'))}. #{redis.zrange(key('running'), 0, -1)}"
67+
puts " Owners: #{redis.hgetall(key('owners'))}"
68+
idle_state_printed = true
69+
end
5770
sleep 0.05
5871
end
5972
end

0 commit comments

Comments
 (0)