Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make queue setup idempotent #287

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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,14 @@ def max_test_failed?

attr_reader :redis, :redis_url

def with_redis_timeout(timeout)
prev = redis._client.timeout
redis._client.timeout = timeout
yield
ensure
redis._client.timeout = prev
end

def measure
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Expand Down
29 changes: 21 additions & 8 deletions ruby/lib/ci/queue/redis/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,28 @@ def push(tests)
puts "Worker electected as leader, pushing #{@total} tests to the queue."
puts

attempts = 0
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)
with_redis_timeout(5) do
redis.without_reconnect 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
rescue ::Redis::BaseError => error
if !queue_initialized? && attempts < 3
ChrisBr marked this conversation as resolved.
Show resolved Hide resolved
zarifmahfuz marked this conversation as resolved.
Show resolved Hide resolved
puts "Retrying pushing #{@total} tests to the queue... (#{error})"
attempts += 1
retry
end

raise if !queue_initialized?
end
end

Expand Down
Loading