lib/runbox/jitter_message.ex

defmodule Runbox.JitterMessage do
  @moduledoc group: :messages
  @moduledoc """
  Formerly delayed messages/late events, when jitter around incoming topic is out of threshold.

  Negative delay means message is too late (from past). Positive delay means message is too early
  (from future).

  Normalized messages is provided.
  """

  alias __MODULE__

  @derive Jason.Encoder
  defstruct [:delay, :normalized, reason: :jitter]

  @typedoc "See module `Runbox.JitterMessage` info."
  @type t :: %JitterMessage{
          delay: integer(),
          normalized: term(),
          reason: :jitter | :rebuffer_discard
        }
end