Skip to content

Commit

Permalink
Add logs around leader election
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBr committed Jun 13, 2024
1 parent 404ab99 commit 916a7cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions ruby/lib/ci/queue/redis/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ def max_test_failed?

attr_reader :redis, :redis_url

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

def key(*args)
['build', build_id, *args].join(':')
end
Expand Down
6 changes: 0 additions & 6 deletions ruby/lib/ci/queue/redis/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ 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
22 changes: 14 additions & 8 deletions ruby/lib/ci/queue/redis/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,21 @@ def push(tests)
@total = tests.size

if @master = redis.setnx(key('master-status'), 'setup')
redis.multi do |transaction|
transaction.lpush(key('queue'), tests) unless tests.empty?
transaction.set(key('total'), @total)
transaction.set(key('master-status'), 'ready')

transaction.expire(key('queue'), config.redis_ttl)
transaction.expire(key('total'), config.redis_ttl)
transaction.expire(key('master-status'), config.redis_ttl)
puts "Worker electected as leader, pushing #{@total} tests to the queue."

duration = measure do
redis.multi do |transaction|
transaction.lpush(key('queue'), tests) unless tests.empty?
transaction.set(key('total'), @total)
transaction.set(key('master-status'), 'ready')

transaction.expire(key('queue'), config.redis_ttl)
transaction.expire(key('total'), config.redis_ttl)
transaction.expire(key('master-status'), config.redis_ttl)
end
end

puts "Finished pushing #{@total} tests to the queue in #{duration} seconds."
end
register
redis.expire(key('workers'), config.redis_ttl)
Expand Down

0 comments on commit 916a7cd

Please sign in to comment.