Module: Dynflow::Executors

Defined in:
lib/dynflow/executors.rb,
lib/dynflow/executors/parallel.rb,
lib/dynflow/executors/sidekiq/core.rb,
lib/dynflow/executors/abstract/core.rb,
lib/dynflow/executors/parallel/core.rb,
lib/dynflow/executors/parallel/pool.rb,
lib/dynflow/executors/parallel/worker.rb,
lib/dynflow/executors/sidekiq/worker_jobs.rb,
lib/dynflow/executors/sidekiq/redis_locking.rb,
lib/dynflow/executors/sidekiq/serialization.rb,
lib/dynflow/executors/sidekiq/internal_job_base.rb,
lib/dynflow/executors/sidekiq/orchestrator_jobs.rb

Defined Under Namespace

Modules: Abstract, Sidekiq Classes: Parallel

Class Method Summary collapse

Class Method Details

.run_user_codeObject

Every time we run a code that can be defined outside of Dynflow, we should wrap it with this method, and we can ensure here to do necessary cleanup, such as cleaning ActiveRecord connections



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dynflow/executors.rb', line 11

def run_user_code
  # Here we cover a case where the connection was already checked out from
  # the pool and had opened transactions. In that case, we should leave the
  # cleanup to the other runtime unit which opened the transaction. If the
  # connection was checked out or there are no opened transactions, we can
  # safely perform the cleanup.
  no_previously_opened_transactions = active_record_open_transactions.zero?
  yield
ensure
  ::ActiveRecord::Base.clear_active_connections! if no_previously_opened_transactions && active_record_connected?
  ::Logging.mdc.clear if defined? ::Logging
end