Karta.Outbound.Warmup (Karta v1.0.0)

The daily limits of sending addresses under a warm-up plan (Karta.IPPools.WarmupPlan), kept by every node and job together.

Each address under a plan has a counter per UTC day in the database (Karta.Outbound.WarmupUsage): the recipients it was used for that day. Before a delivery connects from such an address it reserves the recipients it is about to send to (reserve/3): one transaction locks the day's row, grants as many as the day's limit leaves and counts them at once, so jobs on any number of nodes never pass a limit together. A recipient counts once it is sent to in an SMTP transaction from the address, whatever the server answers; units a delivery did not use (no server took the transaction) are given back (release/3).

An address without a plan, or past its plan's last day, has no limit and no counter. A delivery that finds no address with room waits (wait/1) until the next UTC day, looking again at least every hour (a plan may have been changed, an address added).

For the metrics, report/1 reads where every address's warm-up stands (Karta.PromEx.Limits).

Summary

Functions

The address's limit on date: nil for none (no plan, or past its plan's last day), else the number of recipients (0 before the plan's first day). The address's warmup_plan must be loaded.

Gives back units reserved on the address for day that were not used.

Reports each address in its warm-up on the UTC day date (default today): the telemetry event [:karta, :warmup, :usage] with the measurements sent and limit and the metadata pool and address (text). Addresses past their plan are left out. When the database cannot be read, nothing is reported.

Reserves up to wanted recipients on the address for the UTC day of now: :unlimited when the address has no limit that day, else the number granted (0 once the day's limit is reached), which is counted at once.

The recipients the address was used for on date (counted only while it has a limit).

Seconds a delivery that found no address with room waits: until the next UTC day, at most an hour.

Functions

daily_limit(ip_address, date)

@spec daily_limit(Karta.IPPools.IPAddress.t(), Date.t()) :: non_neg_integer() | nil

The address's limit on date: nil for none (no plan, or past its plan's last day), else the number of recipients (0 before the plan's first day). The address's warmup_plan must be loaded.

release(ip_address, day, units)

@spec release(Karta.IPPools.IPAddress.t(), Date.t(), non_neg_integer()) :: :ok

Gives back units reserved on the address for day that were not used.

report(date \\ Date.utc_today())

@spec report(Date.t()) :: :ok

Reports each address in its warm-up on the UTC day date (default today): the telemetry event [:karta, :warmup, :usage] with the measurements sent and limit and the metadata pool and address (text). Addresses past their plan are left out. When the database cannot be read, nothing is reported.

reserve(address, wanted, now)

@spec reserve(Karta.IPPools.IPAddress.t(), pos_integer(), DateTime.t()) ::
  :unlimited | non_neg_integer()

Reserves up to wanted recipients on the address for the UTC day of now: :unlimited when the address has no limit that day, else the number granted (0 once the day's limit is reached), which is counted at once.

sent(ip_address, date)

The recipients the address was used for on date (counted only while it has a limit).

wait(now)

@spec wait(DateTime.t()) :: pos_integer()

Seconds a delivery that found no address with room waits: until the next UTC day, at most an hour.