fix: retry mysql connections on message DB pool

This commit is contained in:
Adam Cooke
2024-02-13 15:56:40 +00:00
parent b8cb563553
commit f9f7fb30fe
2 changed files with 20 additions and 1 deletions
+9 -1
View File
@@ -12,9 +12,11 @@ module Postal
end
def use
connection = checkout
retried = false
do_not_checkin = false
begin
connection = checkout
yield connection
rescue Mysql2::Error => e
if e.message =~ /(lost connection|gone away|not connected)/i
@@ -22,6 +24,12 @@ module Postal
# we won't add it back in to the pool so that it'll reconnect
# next time.
do_not_checkin = true
# If we haven't retried yet, we'll retry the block once more.
if retried == false
retried = true
retry
end
end
raise