Class: ActsAsTbackend::Pool
- Inherits:
-
Object
- Object
- ActsAsTbackend::Pool
- Defined in:
- lib/acts_as_tbackend/pool.rb
Overview
A pool of persistent Connections — the concurrency layer, kept deliberately
separate from the Connection (protocol) so each can be reasoned about and tested
on its own. Sized to the process's worker threads (≈ Puma threads).
Fork-safety: sockets created before a fork are invalid in the child. Call
ActsAsTbackend.reset! in the forking hook (Puma on_worker_boot, Sidekiq
on(:startup)) so children build fresh connections.
Instance Method Summary collapse
-
#initialize(config) ⇒ Pool
constructor
A new instance of Pool.
- #shutdown ⇒ Object
- #with(&block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Pool
Returns a new instance of Pool.
14 15 16 17 18 19 20 21 22 |
# File 'lib/acts_as_tbackend/pool.rb', line 14 def initialize(config) @pool = ConnectionPool.new(size: config.pool_size, timeout: config.pool_checkout_timeout) do Connection.new( host: config.host, port: config.port, token: config.token, connect_timeout: config.connect_timeout, request_timeout: config.request_timeout, durability_default: config.durability_default, strict: config.strict ) end end |
Instance Method Details
#shutdown ⇒ Object
28 29 30 |
# File 'lib/acts_as_tbackend/pool.rb', line 28 def shutdown @pool.shutdown { |conn| conn.close } end |
#with(&block) ⇒ Object
24 25 26 |
# File 'lib/acts_as_tbackend/pool.rb', line 24 def with(&block) @pool.with(&block) end |