View Source Hedgex.Capture (hedgex v0.3.4)

Buffered + batched async event pipeline.

capture/1 sends the event into a buffer backed by a queue. Events are drained from the queue and sent to the PostHog API when either (1) there are more than flush_batch_size events pending, or (2) flush_interval milliseconds have passed since the previous flush, whichever comes first.

Configuration

config :hedgex, :capture,
  max_queue_size: 10000
  # ... etc

Options:

  • max_queue_size: The size of the queue used to buffer events before sending. If the queue is full, Hedgex.capture/1 will return an error. Defaults to 10000.

  • flush_interval: Interval in milliseconds for sending events to the API. Defaults to 500.

  • flush_batch_size: Max number of events in the queue before sending events to the API. This is best-effort and not a strict limit. Defaults to 100.

Summary

Types

@type options() :: [{:max_queue_size, pos_integer() | nil}]
@type state() :: %{
  queue: :queue.queue(),
  queue_size: pos_integer() | 0,
  pending_demand: pos_integer() | 0,
  max_queue_size: pos_integer()
}

Functions

@spec capture(event :: Hedgex.event()) :: :ok | {:error, :queue_full}
Link to this function

handle_call(arg1, from, state)

View Source
@spec handle_call({:capture, event :: Hedgex.event()}, GenServer.from(), state()) ::
  term()
@spec handle_call(:queue_size, GenServer.from(), state()) :: term()

Callback implementation for GenStage.handle_call/3.

Link to this function

handle_demand(demand, state)

View Source

Callback implementation for GenStage.handle_demand/2.

Callback implementation for GenStage.init/1.

@spec queue_size() :: pos_integer() | 0
@spec start_link(options()) :: GenServer.on_start()