Mxpanel.Batcher (Mxpanel v0.3.0) View Source

Manages a pool of buffers that accumulate the events and sends them to the Mixpanel API in batches in background. It implements a registry-based routing pool with round-robing as routing strategy.

Checkout start_link/1 for all supported options.

Usage

  1. Add to your supervision tree:
{Mxpanel.Batcher, name: MyApp.Batcher, token: "mixpanel project token"}
  1. Enqueue an event:
Mxpanel.track_later(MyApp.MxpanelBatcher, event)
  1. The event will be buffered, and later sent in batch to the Mixpanel API.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Synchronously drain all buffers in the batcher. Returns a list containing all the processed events.

Starts a Mxpanel.Batcher linked to the current process.

Link to this section Types

Specs

name() :: atom()

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

drain_buffers(batcher_name)

View Source

Specs

drain_buffers(name()) :: :ok

Synchronously drain all buffers in the batcher. Returns a list containing all the processed events.

Mxpanel.Batcher.drain_buffers(MyApp.Batcher)

Starts a Mxpanel.Batcher linked to the current process.

Supported options

  • :name - Required. Name of the batcher instance.

  • :token - Required if active. The Mixpanel token associated with your project.

  • :active - Configure Batcher to be active or not. Useful for disabling requests in certain environments. The default value is true.

  • :base_url - Mixpanel API URL The default value is "https://api.mixpanel.com".

  • :http_client - HTTP client used by the Batcher. The default value is {Mxpanel.HTTPClient.HackneyAdapter, []}.

  • :pool_size - The size of the pool of event buffers. The default value is 10.

  • :flush_interval - Interval in milliseconds which the event buffer are processed. The default value is 5000.

  • :flush_jitter - Jitter the flush interval by a random amount. Value in milliseconds. This is primarily to avoid large write spikes. For example, a flush_jitter of 1s and flush_interval of 1s means flushes will happen every 5-6s. The default value is 1000.

  • :retry_max_attempts - Max attempts that a batch of events should be tried before giving up. The default value is 5.

  • :retry_base_backoff - Base time in milliseconds to calculate the wait time between retry attempts. Formula: (attempt * retry_base_backoff) + random(1..retry_base_backoff). The default value is 100.

  • :import_timeout - The maximum amount of time in milliseconds each batch of events is allowed to execute for. The default value is 30000.

  • :telemetry_buffers_info_interval - Interval in milliseconds the telemetry with the buffers info is published. The default value is 30000.

  • :debug - Enable debug logging. The default value is false.