Class: Tpt::Rails::EventBridgePublisher
- Inherits:
-
Object
- Object
- Tpt::Rails::EventBridgePublisher
- Defined in:
- app/models/tpt/rails/event_bridge_publisher.rb
Defined Under Namespace
Classes: NoEntriesInResponseData
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(event_bus_name: default_event_bus_name, event_source: default_event_source, batch_size: 10, client_options: {}) ⇒ EventBridgePublisher
constructor
A new instance of EventBridgePublisher.
- #publish(events) ⇒ Object
Constructor Details
#initialize(event_bus_name: default_event_bus_name, event_source: default_event_source, batch_size: 10, client_options: {}) ⇒ EventBridgePublisher
Returns a new instance of EventBridgePublisher.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/tpt/rails/event_bridge_publisher.rb', line 8 def initialize( event_bus_name: default_event_bus_name, event_source: default_event_source, batch_size: 10, client_options: {} ) @event_bus_name = event_bus_name @event_source = event_source @batch_size = batch_size @client = make_client() end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
5 6 7 |
# File 'app/models/tpt/rails/event_bridge_publisher.rb', line 5 def batch_size @batch_size end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'app/models/tpt/rails/event_bridge_publisher.rb', line 6 def client @client end |
Instance Method Details
#publish(events) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/tpt/rails/event_bridge_publisher.rb', line 20 def publish(events) events = [events] unless events.is_a?(Array) logger.debug "Publishing #{events.length} events to EventBridge in #{events.length/@batch_size} batch(es)" metrics.time('tpt.event_bridge.publish') do events.each_slice(@batch_size) do |batch| publish_batch(batch) end end events end |