class Protobuf::ActiveRecord::Middleware::ConnectionManagementAsync
Constants
- START_MUTEX
Public Class Methods
new(app)
click to toggle source
# File lib/protobuf/active_record/middleware/connection_management_async.rb, line 37 def initialize(app) @app = app end
start_timed_task!()
click to toggle source
# File lib/protobuf/active_record/middleware/connection_management_async.rb, line 10 def self.start_timed_task! if timed_task_started.false? START_MUTEX.synchronize do return if timed_task_started.true? args = { :execution_interval => ::Protobuf::ActiveRecord.config.connection_reaping_interval, :timeout_interval => ::Protobuf::ActiveRecord.config.connection_reaping_timeout_interval } timed_task = ::Concurrent::TimerTask.new(args) do ::ActiveRecord::Base.clear_active_connections! end timed_task.execute timed_task_started.make_true end end end
timed_task_started()
click to toggle source
# File lib/protobuf/active_record/middleware/connection_management_async.rb, line 29 def self.timed_task_started if @timed_task_started.nil? @timed_task_started = ::Concurrent::AtomicBoolean.new(false) end @timed_task_started end
Public Instance Methods
call(env)
click to toggle source
rubocop:disable Lint/DuplicateMethods rubocop:disable Lint/NestedMethodDefinition
# File lib/protobuf/active_record/middleware/connection_management_async.rb, line 43 def call(env) def call(env) ::ActiveRecord::Base.connection_pool.with_connection do @app.call(env) end end self.class.start_timed_task! call(env) end