Follow up - 2c8825b387
- ActiveJobLock PG::TRSerializationFailure exception is actually ActiveRecord::SerializationFailure.
This commit is contained in:
parent
5c6bc72d1b
commit
3d00f4d25b
2 changed files with 19 additions and 21 deletions
|
@ -89,12 +89,12 @@ module HasActiveJobLock
|
||||||
ActiveJobLock.transaction(isolation: :serializable) do
|
ActiveJobLock.transaction(isolation: :serializable) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
rescue ActiveRecord::SerializationFailure => e
|
||||||
# PostgeSQL prevents locking on records that are already locked
|
# PostgeSQL prevents locking on records that are already locked
|
||||||
# for UPDATE in Serializable Isolation Level transactions,
|
# for UPDATE in Serializable Isolation Level transactions,
|
||||||
# but it's safe to retry as described in the docs:
|
# but it's safe to retry as described in the docs:
|
||||||
# https://www.postgresql.org/docs/10/transaction-iso.html
|
# https://www.postgresql.org/docs/10/transaction-iso.html
|
||||||
rescue PG::TRSerializationFailure
|
e.message.include?('PG::TRSerializationFailure') ? retry : raise
|
||||||
retry
|
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
existing_active_job_lock!
|
existing_active_job_lock!
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,8 +101,7 @@ RSpec.describe HasActiveJobLock, type: :job do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
context "when ActiveRecord::SerializationFailure 'PG::TRSerializationFailure: ERROR: could not serialize access due to concurrent update' is raised" do
|
||||||
context "when PG::TRSerializationFailure 'Could not serialize access due to concurrent update' is raised" do
|
|
||||||
|
|
||||||
it 'retries execution until succeed' do
|
it 'retries execution until succeed' do
|
||||||
allow(ActiveRecord::Base.connection).to receive(:open_transactions).and_return(0)
|
allow(ActiveRecord::Base.connection).to receive(:open_transactions).and_return(0)
|
||||||
|
@ -112,7 +111,7 @@ RSpec.describe HasActiveJobLock, type: :job do
|
||||||
|
|
||||||
if !exception_raised
|
if !exception_raised
|
||||||
exception_raised = true
|
exception_raised = true
|
||||||
raise PG::TRSerializationFailure, 'Could not serialize access due to concurrent update'
|
raise ActiveRecord::SerializationFailure, 'PG::TRSerializationFailure: ERROR: could not serialize access due to concurrent update'
|
||||||
end
|
end
|
||||||
|
|
||||||
block.call
|
block.call
|
||||||
|
@ -123,7 +122,6 @@ RSpec.describe HasActiveJobLock, type: :job do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'handle locking of jobs'
|
include_examples 'handle locking of jobs'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue