Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8dab2a57
Commit
8dab2a57
authored
Nov 29, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sidekiq transaction check to be decomposition aware
parent
e43bf390
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletion
+15
-1
config/initializers/forbid_sidekiq_in_transactions.rb
config/initializers/forbid_sidekiq_in_transactions.rb
+7
-1
spec/initializers/forbid_sidekiq_in_transactions_spec.rb
spec/initializers/forbid_sidekiq_in_transactions_spec.rb
+6
-0
spec/spec_helper.rb
spec/spec_helper.rb
+2
-0
No files found.
config/initializers/forbid_sidekiq_in_transactions.rb
View file @
8dab2a57
...
...
@@ -20,7 +20,7 @@ module Sidekiq
module
NoEnqueueingFromTransactions
%i(perform_async perform_at perform_in)
.
each
do
|
name
|
define_method
(
name
)
do
|*
args
|
if
!
Sidekiq
::
Worker
.
skip_transaction_check
&&
ApplicationRecord
.
inside_transaction?
if
!
Sidekiq
::
Worker
.
skip_transaction_check
&&
inside_transaction?
begin
raise
Sidekiq
::
Worker
::
EnqueueFromTransactionError
,
<<~
MSG
`
#{
self
}
.
#{
name
}
` cannot be called inside a transaction as this can lead to
...
...
@@ -38,6 +38,12 @@ module Sidekiq
super
(
*
args
)
end
end
private
def
inside_transaction?
::
ApplicationRecord
.
inside_transaction?
||
::
Ci
::
ApplicationRecord
.
inside_transaction?
end
end
prepend
NoEnqueueingFromTransactions
...
...
spec/initializers/forbid_sidekiq_in_transactions_spec.rb
View file @
8dab2a57
...
...
@@ -29,4 +29,10 @@ RSpec.describe 'Sidekiq::Worker' do
end
end
end
it
'forbids queue sidekiq worker in a Ci::ApplicationRecord transaction'
do
Ci
::
Pipeline
.
transaction
do
expect
{
worker_class
.
perform_async
}.
to
raise_error
(
Sidekiq
::
Worker
::
EnqueueFromTransactionError
)
end
end
end
spec/spec_helper.rb
View file @
8dab2a57
...
...
@@ -239,6 +239,7 @@ RSpec.configure do |config|
# is not yet opened at the time that is triggered
config
.
prepend_before
do
ApplicationRecord
.
set_open_transactions_baseline
::
Ci
::
ApplicationRecord
.
set_open_transactions_baseline
end
config
.
append_before
do
...
...
@@ -247,6 +248,7 @@ RSpec.configure do |config|
config
.
append_after
do
ApplicationRecord
.
reset_open_transactions_baseline
::
Ci
::
ApplicationRecord
.
reset_open_transactions_baseline
end
config
.
before
do
|
example
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment