Module: Wurk::Web::PoolScope
- Defined in:
- lib/wurk/web/pool_scope.rb
Overview
Routes Wurk.redis onto the dedicated web pool (Wurk::Configuration
#web_redis_pool) for the duration of a block.
The dashboard, JSON API, and SSE stream run in the host's web process and
reach Redis through the same inspector objects (Stats, Queue, Search, …) a
worker uses — all of which call Wurk.redis. Left on the default pool, a
burst of dashboard traffic or a long-held SSE stream could drain the
connections a co-located (embedded) worker needs to make progress, and
vice versa: the #101 pool-exhaustion incident.
Wurk.redis_pool resolves its pool by calling #redis_pool on
Thread.current[:wurk_capsule] (falling back to the default capsule).
Pointing that thread-local at a handle whose #redis_pool is the web pool
diverts every nested Wurk.redis call with no per-call-site change. The
prior value is restored on exit so a reused web-server thread — or a
nested scope — is left untouched.
Defined Under Namespace
Classes: Handle
Class Method Summary collapse
Class Method Details
.handle ⇒ Object
31 32 33 |
# File 'lib/wurk/web/pool_scope.rb', line 31 def handle @handle ||= Handle.new end |
.scope ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/wurk/web/pool_scope.rb', line 23 def scope prev = Thread.current[:wurk_capsule] Thread.current[:wurk_capsule] = handle yield ensure Thread.current[:wurk_capsule] = prev end |