Karta.Reports.Sending.Kind behaviour (Karta v1.0.0)

What a kind of report knows: which domains it has something to report about for a day, the reports to send about one, and where to send them. Karta.Reports.Sending.Runner does the rest (limits, sending, records, retries) and is the same for every kind.

A report is a map: :id (its identifier, also the base of its Message-ID), :records (how many records it holds), :subject, :text (the message's text), :filename, :content_type, :data (the attachment, compressed) and :headers (further header fields). A report that was split has several, numbered by their position.

Summary

Types

What the runner tells a kind about the reporter.

Callbacks

The addresses to send the reports about domain to, or why there are none ({:skip, reason}), or {:error, :dns} when the answer could not be found out now. deadline is a monotonic time in milliseconds.

The domains (at most limit, the busiest first) with something to report for day.

The kind's name as stored in report_runs.kind.

The reports about domain for day, or :empty when there is nothing.

Types

context()

@type context() :: %{
  from: Karta.Mail.Address.t(),
  host: String.t(),
  now: DateTime.t()
}

What the runner tells a kind about the reporter.

report()

@type report() :: %{
  id: String.t(),
  records: non_neg_integer(),
  subject: String.t(),
  text: String.t(),
  filename: String.t(),
  content_type: String.t(),
  data: binary(),
  headers: [{String.t(), String.t()}]
}

Callbacks

destinations(t, integer)

@callback destinations(String.t(), integer()) ::
  {:ok, [String.t()]} | {:skip, String.t()} | {:error, :dns}

The addresses to send the reports about domain to, or why there are none ({:skip, reason}), or {:error, :dns} when the answer could not be found out now. deadline is a monotonic time in milliseconds.

domains(t, pos_integer)

@callback domains(Date.t(), pos_integer()) :: [String.t()]

The domains (at most limit, the busiest first) with something to report for day.

name()

@callback name() :: String.t()

The kind's name as stored in report_runs.kind.

reports(t, t, context)

@callback reports(String.t(), Date.t(), context()) :: {:ok, [report()]} | :empty

The reports about domain for day, or :empty when there is nothing.