Class: Hackle::UserEventDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hackle/internal/event/user_event_dispatcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_client:, executor:, serializer:) ⇒ UserEventDispatcher

Returns a new instance of UserEventDispatcher.

Parameters:



11
12
13
14
15
16
17
18
# File 'lib/hackle/internal/event/user_event_dispatcher.rb', line 11

def initialize(http_client:, executor:, serializer:)
  # @type [HttpClient]
  @http_client = http_client
  # @type [ThreadPoolExecutor]
  @executor = executor
  @serializer = serializer
  @url = '/api/v2/events'
end

Class Method Details

.create(http_client:, executor:) ⇒ Object

Parameters:

  • http_client (HttpClient)
  • executor (ThreadPoolExecutor)


22
23
24
25
26
27
28
# File 'lib/hackle/internal/event/user_event_dispatcher.rb', line 22

def self.create(http_client:, executor:)
  UserEventDispatcher.new(
    http_client: http_client,
    executor: executor,
    serializer: UserEventSerializer.new
  )
end

Instance Method Details

#dispatch(events) ⇒ Object

Parameters:



31
32
33
34
35
36
37
38
# File 'lib/hackle/internal/event/user_event_dispatcher.rb', line 31

def dispatch(events)
  payload = @serializer.serialize(events)
  begin
    @executor.post { dispatch_internal(payload) }
  rescue => e
    Log.get.error { "Unexpected error while posting events: #{e.inspect}" }
  end
end

#shutdownObject



40
41
42
43
44
45
# File 'lib/hackle/internal/event/user_event_dispatcher.rb', line 40

def shutdown
  @executor.shutdown
  return if @executor.wait_for_termination(10)

  Log.get.warn { 'Failed to dispatch previously submitted events' }
end