Segmentry.Analytics.Batcher (segmentry v0.3.0)

Copy Markdown View Source

Default service implementation. Uses the Segment Batch HTTP API to put events in a FIFO queue and send on a regular basis.

config :segmentry,
  max_batch_size: 100,
  batch_every_ms: 5000
  • :max_batch_size — maximum batch size sent per request. Default 100.
  • :batch_every_ms — interval (ms) between batch flushes. Default 2000.

Segment limits batch requests to 500KB and individual calls to 32KB. The library does not enforce this directly — keep max_batch_size low if your events are large. Segment also asks callers to limit themselves to under 50 requests/second; do not set batch_every_ms under 20ms.

Summary

Functions

Enqueue a Segment event for the next batch. Must be a Track, Identify, Screen, Alias, Group, or Page struct.

Returns a specification to start this module under a supervisor.

Force the batcher to flush the queue immediately.

Start the GenServer with a Segment HTTP Source API write key.

Start the GenServer with a Segment HTTP Source API write key and a keyword list of Req options. Used in tests to inject a Req.Test plug stub.

Functions

call(event)

@spec call(Segmentry.segment_event()) :: :ok

Enqueue a Segment event for the next batch. Must be a Track, Identify, Screen, Alias, Group, or Page struct.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush()

@spec flush() :: :ok

Force the batcher to flush the queue immediately.

start_link(api_key)

@spec start_link(String.t()) :: GenServer.on_start()

Start the GenServer with a Segment HTTP Source API write key.

start_link(api_key, req_options)

@spec start_link(
  String.t(),
  keyword()
) :: GenServer.on_start()

Start the GenServer with a Segment HTTP Source API write key and a keyword list of Req options. Used in tests to inject a Req.Test plug stub.