Class: JetstreamBridge::BatchPublisher::BatchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/jetstream_bridge/publisher/batch_publisher.rb

Overview

Result object for batch operations.

Contains aggregated results from a batch publish operation, including success/failure counts and detailed error information.

Examples:

Checking results

results = JetstreamBridge.publish_batch { |b| ... }
puts "Success: #{results.successful_count}"
puts "Failed: #{results.failed_count}"
puts "Partial: #{results.partial_success?}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ BatchResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BatchResult.

Parameters:



58
59
60
61
62
63
64
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 58

def initialize(results)
  @results = results
  @successful_count = results.count(&:success?)
  @failed_count = results.count(&:failure?)
  @errors = results.select(&:failure?).map { |r| { event_id: r.event_id, error: r.error } }
  freeze
end

Instance Attribute Details

#errorsArray<Hash> (readonly)

Returns Array of error details with event_id and error.

Returns:

  • (Array<Hash>)

    Array of error details with event_id and error



54
55
56
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 54

def errors
  @errors
end

#failed_countInteger (readonly)

Returns Number of failed events.

Returns:

  • (Integer)

    Number of failed events



52
53
54
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 52

def failed_count
  @failed_count
end

#resultsArray<Models::PublishResult> (readonly)

Returns All individual publish results.

Returns:



48
49
50
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 48

def results
  @results
end

#successful_countInteger (readonly)

Returns Number of successfully published events.

Returns:

  • (Integer)

    Number of successfully published events



50
51
52
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 50

def successful_count
  @successful_count
end

Instance Method Details

#failure?Boolean

Check if any events failed to publish.

Returns:

  • (Boolean)

    True if any failures



76
77
78
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 76

def failure?
  !success?
end

#partial_success?Boolean

Check if some (but not all) events published successfully.

Returns:

  • (Boolean)

    True if both successes and failures exist



83
84
85
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 83

def partial_success?
  @successful_count.positive? && @failed_count.positive?
end

#success?Boolean

Check if all events published successfully.

Returns:

  • (Boolean)

    True if no failures



69
70
71
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 69

def success?
  @failed_count.zero?
end

#to_hObject Also known as: to_hash



87
88
89
90
91
92
93
94
# File 'lib/jetstream_bridge/publisher/batch_publisher.rb', line 87

def to_h
  {
    successful_count: @successful_count,
    failed_count: @failed_count,
    total_count: @results.size,
    errors: @errors
  }
end