Karta.Outbound.Limits (Karta v1.0.0)

How many of a delivery run's recipients may be sent to now, and from which of the IP pool's addresses: the limits per destination (Karta.Outbound.Throttle) and the warm-up limits of the addresses (Karta.Outbound.Warmup).

A run asks once (admit/4), when the recipient's mail servers are known and before the message is read or anything sent, and says afterwards how many recipients each IP family's address was used for (done/2), so that what was reserved and not used is given back.

Destination. The run's destination is its first mail server, the most preferred: the rules (the pool's own destination_limits, else the :destination_limits option) say which group of MX hosts it belongs to and the group's limits. The run takes one connection slot of the group, for its pool, until it ends, and as many recipients as the minute has room for; without a slot or room it waits.

Which address. For each IP family of the mail servers, in their order, the pool's addresses this node holds are tried from the message's own (its retries keep coming from that address while it has room: greylisting remembers the address) through the others; the first without a limit, or with room left today, is used. The first family that has room decides how many recipients go now: all of them, or as many as its address has room for; the others wait and are sent by the next run. Another family is used only if one of its addresses has room for as many; otherwise its mail servers are not tried in this run. With no room anywhere the run waits (Karta.Outbound.Warmup.wait/1).

Recipients held back are reported with the telemetry event [:karta, :delivery, :held_back]: the measurement recipients, the metadata reason (:connections, :rate or :warmup) and pool (its name, or "" without a pool).

Summary

Functions

Admits up to wanted recipients of a run to targets (the mail servers, Karta.Outbound.MXResolver) from sources: nil for a server without an IP pool, else the held addresses of each family, the message's own first. Options: :now (the time), :destination_limits (Karta.Outbound.Throttle rules for servers without a pool and pools without their own) and :throttle (its server; default Karta.Outbound.Throttle).

After the run: used is the number of recipients each IP family's address was used for in a transaction (%{4 => 3}); the rest of what was reserved is given back.

Types

family()

@type family() :: 4 | 8

permit()

@type permit() ::
  %{
    throttle: {GenServer.server(), reference(), pos_integer()} | nil,
    warmup: %{
      required(family()) =>
        {Karta.IPPools.IPAddress.t(), Date.t(), pos_integer()}
    }
  }
  | nil

reason()

@type reason() :: :warmup | {:connections | :rate, String.t()}

sources()

@type sources() ::
  %{
    pool: Karta.IPPools.IPPool.t(),
    by_family: %{required(family()) => [Karta.IPPools.IPAddress.t()]}
  }
  | nil

Functions

admit(targets, wanted, sources, opts)

@spec admit([map(), ...], pos_integer(), sources(), keyword()) ::
  {:ok, pos_integer(), sources(), [map(), ...], permit()}
  | {:wait, pos_integer(), reason()}

Admits up to wanted recipients of a run to targets (the mail servers, Karta.Outbound.MXResolver) from sources: nil for a server without an IP pool, else the held addresses of each family, the message's own first. Options: :now (the time), :destination_limits (Karta.Outbound.Throttle rules for servers without a pool and pools without their own) and :throttle (its server; default Karta.Outbound.Throttle).

  • {:ok, admitted, sources, targets, permit} - admitted recipients (the first ones) go now, from the one address per family in sources, to the targets of those families; done/2 takes the permit after the run.
  • {:wait, seconds, reason} - none may go before seconds; reason is :warmup, or {:connections, group} or {:rate, group} for a destination's limit.

done(arg1, used)

@spec done(permit(), %{required(family()) => non_neg_integer()}) :: :ok

After the run: used is the number of recipients each IP family's address was used for in a transaction (%{4 => 3}); the rest of what was reserved is given back.