Skip to content

Commit 10eb26b

Browse files
Merge pull request #38 from figma/ck/fix-broken-code
Fix code broken from the merge with michaelnyu/ci-queue
2 parents 626a8da + e623d4c commit 10eb26b

File tree

5 files changed

+270
-311
lines changed

5 files changed

+270
-311
lines changed

.github/workflows/cla.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ def wait_for_workers
2626

2727
time_left = config.report_timeout - duration.to_i
2828
time_left_with_no_workers = config.inactive_workers_timeout
29+
last_heartbeat_time = Time.now
2930
until exhausted? || time_left <= 0 || max_test_failed? || time_left_with_no_workers <= 0
3031
time_left -= 1
3132
sleep 1
3233

34+
# Heartbeat log every 5 minutes
35+
if Time.now - last_heartbeat_time > 300
36+
puts '[ci-queue] Still working'
37+
last_heartbeat_time = Time.now
38+
end
39+
3340
if active_workers?
3441
time_left_with_no_workers = config.inactive_workers_timeout
3542
else

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

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,10 @@ def master?
4848

4949
def poll
5050
wait_for_master
51-
last_heartbeat_time = Time.now
5251
until shutdown_required? || config.circuit_breakers.any?(&:open?) || exhausted? || max_test_failed?
5352
if test = reserve
5453
yield index.fetch(test)
5554
else
56-
# Log heartbeat every 5 minutes if this is the master process
57-
if master? && Time.now - last_heartbeat_time > 300
58-
puts '[ci-queue] Still working'
59-
last_heartbeat_time = Time.now
60-
end
6155
sleep 0.05
6256
end
6357
end
@@ -209,34 +203,15 @@ def push(tests)
209203

210204
if @master = redis.setnx(key('master-status'), 'setup')
211205
puts "Worker electected as leader, pushing #{@total} tests to the queue."
212-
puts
213-
214-
attempts = 0
215-
duration = measure do
216-
with_redis_timeout(5) do
217-
redis.without_reconnect do
218-
redis.multi do |transaction|
219-
transaction.lpush(key('queue'), tests) unless tests.empty?
220-
transaction.set(key('total'), @total)
221-
transaction.set(key('master-status'), 'ready')
222-
223-
transaction.expire(key('queue'), config.redis_ttl)
224-
transaction.expire(key('total'), config.redis_ttl)
225-
transaction.expire(key('master-status'), config.redis_ttl)
226-
end
227-
end
228-
rescue ::Redis::BaseError => error
229-
if !queue_initialized? && attempts < 3
230-
puts "Retrying pushing #{@total} tests to the queue... (#{error})"
231-
attempts += 1
232-
retry
233-
end
234-
235-
raise if !queue_initialized?
236-
end
206+
redis.multi do |transaction|
207+
transaction.lpush(key('queue'), tests) unless tests.empty?
208+
transaction.set(key('total'), @total)
209+
transaction.set(key('master-status'), 'ready')
210+
211+
transaction.expire(key('queue'), config.redis_ttl)
212+
transaction.expire(key('total'), config.redis_ttl)
213+
transaction.expire(key('master-status'), config.redis_ttl)
237214
end
238-
239-
puts "Finished pushing #{@total} tests to the queue in #{duration.round(2)}s."
240215
end
241216
register
242217
redis.expire(key('workers'), config.redis_ttl)

ruby/lib/minitest/queue.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def run_from_queue(reporter, *)
266266
reopen_previous_step
267267
puts red("The heartbeat process died. This worker is exiting early.")
268268
exit!(41)
269-
rescue CI::Queue::Error
269+
rescue CI::Queue::Error => error
270270
reopen_previous_step
271271
puts red("#{error.class}: #{error.message}")
272272
error.backtrace.each do |frame|

0 commit comments

Comments
 (0)