Module: AfterCommitQueue

Instance Method Summary collapse

Instance Method Details

#run_after_commit(&block) ⇒ Object


11
12
13
14
15
# File 'lib/after_commit_queue.rb', line 11

def run_after_commit(&block)
  _after_commit_queue << block if block

  true
end

#run_after_commit_or_now(&block) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/after_commit_queue.rb', line 17

def run_after_commit_or_now(&block)
  if Gitlab::Database.inside_transaction?
    if ActiveRecord::Base.connection.current_transaction.records.include?(self)
      run_after_commit(&block)
    else
      # If the current transaction does not include this record, we can run
      # the block now, even if it queues a Sidekiq job.
      Sidekiq::Worker.skipping_transaction_check do
        instance_eval(&block)
      end
    end
  else
    instance_eval(&block)
  end

  true
end