Class: Karafka::Persistence::Controller
- Inherits:
-
Object
- Object
- Karafka::Persistence::Controller
- Defined in:
- lib/karafka/persistence/controller.rb
Overview
Module used to provide a persistent cache across batch requests for a given topic and partition to store some additional details when the persistent mode for a given topic is turned on
Constant Summary collapse
- PERSISTENCE_SCOPE =
Thread.current scope under which we store controllers data
:controllers
Class Method Summary collapse
-
.all ⇒ Hash
Current thread persistence scope hash with all the controllers.
-
.fetch(topic, partition) ⇒ Karafka::BaseController
Used to build (if block given) and/or fetch a current controller instance that will be used to process messages from a given topic and partition.
Class Method Details
.all ⇒ Hash
Returns current thread persistence scope hash with all the controllers.
16 17 18 |
# File 'lib/karafka/persistence/controller.rb', line 16 def all Thread.current[PERSISTENCE_SCOPE] ||= {} end |
.fetch(topic, partition) ⇒ Karafka::BaseController
Used to build (if block given) and/or fetch a current controller instance that will be
used to process from a given topic and partition
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/karafka/persistence/controller.rb', line 25 def fetch(topic, partition) all[topic.id] ||= {} # We always store a current instance if topic.persistent all[topic.id][partition] ||= yield else all[topic.id][partition] = yield end end |