-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from openstax/retry_prepared_statement_cache_…
…expired Retry ActiveRecord::PreparedStatementCacheExpired exceptions
- Loading branch information
Showing
5 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# TransactionRetry.max_retries = 3 | ||
# TransactionRetry.wait_times = [0, 1, 2, 4, 8, 16, 32] # seconds to sleep after retry n | ||
TransactionRetry.retry_on = ActiveRecord::PreparedStatementCacheExpired # or an array of classes is valid too (ActiveRecord::TransactionIsolationConflict is by default always included) | ||
# TransactionRetry.before_retry = ->(retry_num, error) { ... } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rails_helper' | ||
|
||
# Need truncation: true because transaction_retry only retries top-level transactions | ||
RSpec.describe TransactionRetry, type: :lib, truncation: true do | ||
it 'retries ActiveRecord::PreparedStatementCacheExpired' do | ||
result = nil | ||
|
||
ActiveRecord::Base.transaction do | ||
if result.nil? | ||
result = 21 | ||
|
||
raise ActiveRecord::PreparedStatementCacheExpired.new('test') | ||
else | ||
result = 42 | ||
end | ||
end | ||
|
||
expect(result).to eq 42 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters