Class: Dionysus::Consumer::ParamsBatchProcessor
- Inherits:
-
Object
- Object
- Dionysus::Consumer::ParamsBatchProcessor
- Defined in:
- lib/dionysus/consumer/params_batch_processor.rb
Instance Method Summary collapse
-
#initialize(config, topic) ⇒ ParamsBatchProcessor
constructor
A new instance of ParamsBatchProcessor.
- #process(batch, batch_number) ⇒ Object
Constructor Details
#initialize(config, topic) ⇒ ParamsBatchProcessor
Returns a new instance of ParamsBatchProcessor.
7 8 9 10 |
# File 'lib/dionysus/consumer/params_batch_processor.rb', line 7 def initialize(config, topic) @config = config @topic = topic end |
Instance Method Details
#process(batch, batch_number) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dionysus/consumer/params_batch_processor.rb', line 12 def process(batch, batch_number) processed_events = [] instrument("dionysus.consume.#{topic}.batch_number_#{batch_number}") do payload = batch.payload.to_h = batch. = payload["message"].to_a with_mutex(, config) do .each do |current_event| event_name = current_event["event"] data = Array.wrap(current_event["data"]) model_name = current_event["model_name"] transformed_data = nil config.instrumenter.instrument("dionysus.consume.#{topic}.batch_number_#{batch_number}.deserialize") do transformed_data = Dionysus::Consumer::Deserializer.new(data).deserialize end if ( = (topic, , transformed_data)) .(topic: topic, message: , transformed_data: transformed_data) next end dionysus_event = Dionysus::Consumer::DionysusEvent.new(event_name, model_name, transformed_data) config.instrumenter.instrument("dionysus.consume.#{topic}.batch_number_#{batch_number}.persist", dionysus_event.to_h.except(:transformed_data, :local_changes)) do config.transaction_provider.connection_pool.with_connection do Dionysus::Consumer::Persistor.new(config, topic).persist(dionysus_event, batch_number) end end processed_events << dionysus_event end end end processed_events end |