Class: Phobos::Actions::ProcessBatch
- Inherits:
-
Object
- Object
- Phobos::Actions::ProcessBatch
- Includes:
- Instrumentation
- Defined in:
- lib/phobos/actions/process_batch.rb
Constant Summary
Constants included from Instrumentation
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(listener:, batch:, listener_metadata:) ⇒ ProcessBatch
constructor
A new instance of ProcessBatch.
Methods included from Instrumentation
#instrument, #measure, subscribe, unsubscribe
Constructor Details
#initialize(listener:, batch:, listener_metadata:) ⇒ ProcessBatch
Returns a new instance of ProcessBatch.
6 7 8 9 10 |
# File 'lib/phobos/actions/process_batch.rb', line 6 def initialize(listener:, batch:, listener_metadata:) @listener = listener @batch = batch @listener_metadata = end |
Instance Method Details
#execute ⇒ 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 51 52 53 54 55 56 57 58 |
# File 'lib/phobos/actions/process_batch.rb', line 12 def execute @batch..each do || backoff = @listener.create_exponential_backoff = @listener_metadata.merge( key: .key, partition: .partition, offset: .offset, retry_count: 0 ) begin instrument('listener.process_message', ) do || time_elapsed = measure do Phobos::Actions::ProcessMessage.new( listener: @listener, message: , metadata: , encoding: @listener.encoding ).execute end .merge!(time_elapsed: time_elapsed) end rescue => e retry_count = [:retry_count] interval = backoff.interval_at(retry_count).round(2) error = { waiting_time: interval, exception_class: e.class.name, exception_message: e., backtrace: e.backtrace } instrument('listener.retry_handler_error', error.merge()) do Phobos.logger.error do { message: "error processing message, waiting #{interval}s" }.merge(error).merge() end sleep interval .merge!(retry_count: retry_count + 1) end raise Phobos::AbortError if @listener.should_stop? retry end end end |