Class: Tpt::Rails::EventBridgePublisher

Inherits:
Object
  • Object
show all
Defined in:
app/models/tpt/rails/event_bridge_publisher.rb

Defined Under Namespace

Classes: NoEntriesInResponseData

Instance Attribute Summary collapse

Instance Method Summary collapse

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(client_options)
end

Instance Attribute Details

#batch_sizeObject

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

#clientObject (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