Sha256: 1db8a8618a8d3ec60bd9a604e9d8d0c6876d1b284c0b9e0be574a5c40c5ae407
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
# frozen_string_literal: true module Dynflow module Executors require 'dynflow/executors/parallel' class << self # 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 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 private def active_record_open_transactions active_record_active_connection&.open_transactions || 0 end def active_record_active_connection return unless defined?(::ActiveRecord) && ::ActiveRecord::Base.connected? # #active_connection? returns the connection if already established or nil ::ActiveRecord::Base.connection_pool.active_connection? end def active_record_connected? !!active_record_active_connection end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dynflow-1.9.0 | lib/dynflow/executors.rb |
dynflow-1.8.3 | lib/dynflow/executors.rb |