Skip to content

Commit

Permalink
Use LockWaitTimeout in lock retrier
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Dec 20, 2023
1 parent 5469b94 commit 07460cd
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/online_migrations/lock_retrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ def with_lock_retries(&block)
else
yield
end
# ActiveRecord::LockWaitTimeout can be used for Active Record 5.2+
rescue ActiveRecord::StatementInvalid => e
if lock_timeout_error?(e) && current_attempt <= attempts
rescue ActiveRecord::LockWaitTimeout
if current_attempt <= attempts
current_delay = delay(current_attempt)
Utils.say("Lock timeout. Retrying in #{current_delay} seconds...")
sleep(current_delay)
Expand All @@ -122,10 +121,6 @@ def with_lock_timeout(value)
ensure
connection.execute("SET lock_timeout TO #{connection.quote(prev_value)}")
end

def lock_timeout_error?(error)
error.message.include?("canceling statement due to lock timeout")
end
end

# `LockRetrier` implementation that has a constant delay between tries
Expand Down

0 comments on commit 07460cd

Please sign in to comment.