Skip to content

Commit dd806bf

Browse files
committed
Increase sleep timeout when polling
1 parent b8cb0c3 commit dd806bf

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ module Queue
77
module Redis
88
class << self
99
attr_accessor :requeue_offset
10+
attr_accessor :max_sleep_time
1011
end
1112
self.requeue_offset = 42
13+
self.max_sleep_time = 2
1214

1315
class Worker < Base
1416
attr_reader :total
@@ -46,13 +48,21 @@ def master?
4648
@master
4749
end
4850

51+
DEFAULT_SLEEP_SECONDS = 0.5
52+
4953
def poll
5054
wait_for_master
55+
attempt = 0
5156
until shutdown_required? || config.circuit_breakers.any?(&:open?) || exhausted? || max_test_failed?
5257
if test = reserve
58+
attempt = 0
5359
yield index.fetch(test)
5460
else
55-
sleep 0.05
61+
# Adding exponential backoff to avoid hammering Redis
62+
# we just stay online here in case a test gets retried or times out so we can afford to wait
63+
sleep_time = [DEFAULT_SLEEP_SECONDS * (2 ** attempt), Redis.max_sleep_time].min
64+
attempt += 1
65+
sleep sleep_time
5666
end
5767
end
5868
redis.pipelined do |pipeline|

ruby/test/fixtures/test/lost_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# frozen_string_literal: true
22
require 'test_helper'
33

4+
CI::Queue::Redis.max_sleep_time = 0.05
5+
46
class LostTest < Minitest::Test
7+
58
def test_foo
69
sleep 3
710
end

0 commit comments

Comments
 (0)