Class: Hackle::UserEventDispatcher
- Inherits:
-
Object
- Object
- Hackle::UserEventDispatcher
- Defined in:
- lib/hackle/internal/event/user_event_dispatcher.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dispatch(events) ⇒ Object
-
#initialize(http_client:, executor:, serializer:) ⇒ UserEventDispatcher
constructor
A new instance of UserEventDispatcher.
- #shutdown ⇒ Object
Constructor Details
#initialize(http_client:, executor:, serializer:) ⇒ UserEventDispatcher
Returns a new instance of UserEventDispatcher.
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
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
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 |
#shutdown ⇒ Object
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 |