Class: SemanticLogger::QueueProcessor::BatchFailure

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_logger/queue_processor/batch_failure.rb

Overview

Internal: what became of a batch of log messages whose write raised a message error (see Subscriber#message_error?), as the appender tells from the error, for the worker thread of a queue processor to carry on with: how many of them the destination stored, those to discard, and the parts of the batch to write again.

When the appender says which message the destination rejected, having stored those before it (see Subscriber#rejected_entry), those before it were written, it is discarded, and those after it are written again as a batch. Otherwise, when the appender's #batch is all or nothing (see Subscriber#batch_all_or_nothing?), the batch is split in half, and each half written again, so that only the messages at fault are discarded, unless the error would fail any batch (see Subscriber#fails_any_batch?). Any other batch is discarded, since writing it again could write some of its messages twice.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(appender, logs, exception) ⇒ BatchFailure

Returns a new instance of BatchFailure.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/semantic_logger/queue_processor/batch_failure.rb', line 25

def initialize(appender, logs, exception)
  @appender  = appender
  @exception = exception
  @written   = 0
  @discarded = []
  @parts     = []
  rejected   = rejected_entry(logs)
  if rejected
    after_rejected(logs, rejected)
  elsif logs.size == 1 || !appender.batch_all_or_nothing? || fails_any_batch?
    @discarded = logs
  else
    @parts = logs.each_slice((logs.size + 1) / 2).to_a
  end
end

Instance Attribute Details

#discarded ⇒ Object (readonly)

Returns [Array] the messages to discard.



20
21
22
# File 'lib/semantic_logger/queue_processor/batch_failure.rb', line 20

def discarded
  @discarded
end

#parts ⇒ Object (readonly)

Returns [Array<Array>] the parts of the batch to write again, in order.



23
24
25
# File 'lib/semantic_logger/queue_processor/batch_failure.rb', line 23

def parts
  @parts
end

#written ⇒ Object (readonly)

Returns [Integer] how many of the messages, from the first, the destination stored.



17
18
19
# File 'lib/semantic_logger/queue_processor/batch_failure.rb', line 17

def written
  @written
end