From b403d0c0bfe5d69b9bebad423a4364379496f46e Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 11 Dec 2023 10:02:32 +0100 Subject: [PATCH] Ruby/Redis: retry connection errors more agressively Booting a CI worker is costly, so in case of a Redis blip, it makes sense to retry for a while before giving up. --- ruby/lib/ci/queue/redis.rb | 1 + ruby/lib/ci/queue/redis/base.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ruby/lib/ci/queue/redis.rb b/ruby/lib/ci/queue/redis.rb index 526c4aed..89031b54 100644 --- a/ruby/lib/ci/queue/redis.rb +++ b/ruby/lib/ci/queue/redis.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +gem 'redis', '>= 5' require 'redis' require 'ci/queue/redis/build_record' require 'ci/queue/redis/base' diff --git a/ruby/lib/ci/queue/redis/base.rb b/ruby/lib/ci/queue/redis/base.rb index f8bba79e..dd8211f2 100644 --- a/ruby/lib/ci/queue/redis/base.rb +++ b/ruby/lib/ci/queue/redis/base.rb @@ -13,7 +13,12 @@ class Base def initialize(redis_url, config) @redis_url = redis_url - @redis = ::Redis.new(url: redis_url) + @redis = ::Redis.new( + url: redis_url, + # Booting a CI worker is costly, so in case of a Redis blip, + # it makes sense to retry for a while before giving up. + reconnect_attempts: [0, 0, 0.1, 0.5, 1, 3, 5], + ) @config = config end