diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-03-05 11:31:23 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-03-05 11:31:23 +0000 |
commit | 477c83f6bbbc9d0a447826900d45207e145e7261 (patch) | |
tree | 05dc4768869fc00c6767bbb9d6bf60da697b7776 | |
parent | b7cacaaf4fedd3d9b3b19ea3f1fe3eb585112b88 (diff) | |
download | gitlab-ce-477c83f6bbbc9d0a447826900d45207e145e7261.tar.gz |
Ports https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4747 to CEbackport-ee-5049-to-ce
-rw-r--r-- | config/initializers/forbid_sidekiq_in_transactions.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/config/initializers/forbid_sidekiq_in_transactions.rb b/config/initializers/forbid_sidekiq_in_transactions.rb index cb611aa21df..4cf1d455eb4 100644 --- a/config/initializers/forbid_sidekiq_in_transactions.rb +++ b/config/initializers/forbid_sidekiq_in_transactions.rb @@ -18,13 +18,26 @@ module Sidekiq %i(perform_async perform_at perform_in).each do |name| define_method(name) do |*args| if !Sidekiq::Worker.skip_transaction_check && AfterCommitQueue.inside_transaction? - raise Sidekiq::Worker::EnqueueFromTransactionError, <<~MSG + begin + raise Sidekiq::Worker::EnqueueFromTransactionError, <<~MSG `#{self}.#{name}` cannot be called inside a transaction as this can lead to race conditions when the worker runs before the transaction is committed and tries to access a model that has not been saved yet. Use an `after_commit` hook, or include `AfterCommitQueue` and use a `run_after_commit` block instead. - MSG + MSG + rescue Sidekiq::Worker::EnqueueFromTransactionError => e + if Rails.env.production? + Rails.logger.error(e.message) + + if Gitlab::Sentry.enabled? + Gitlab::Sentry.context + Raven.capture_exception(e) + end + else + raise + end + end end super(*args) |