Karta. Outbound. Actions
(Karta v1.0.0)
What an operator may do to an outgoing message that is still to be
delivered: retry it now, hold it and release it, and
cancel it while it is scheduled. Each is judged recipient by
recipient, in one statement that names the states it may act on, and
written to the audit log (Karta.Audit) in the same transaction.
| Action | Acts on | Does |
|---|---|---|
retry/4 | :queued or :deferred, not held, not due now, not being sent | makes it due now and queues a delivery job |
hold/4 | :queued or :deferred, not held | sets held_at; nothing sends it |
release/4 | held | clears held_at and queues a delivery job |
cancel/4 | :queued, never tried, due in the future (a scheduled message) | :cancelled; never tried |
A recipient that is :delivered, :bounced, :suppressed or
:cancelled is final and no action touches it: a message that was
delivered cannot be sent again by accident. An action that finds nothing
to act on changes nothing and says why ({:error, {:conflict, reason}},
reason one of :final, :held, :not_held, :being_sent,
:due_now, :not_scheduled).
Held means not claimed. Delivery takes the recipients it sends with
one conditional update that names the states :queued and :deferred
and requires held_at to be empty (Karta.Outbound.Deliverer, and
Karta.Claim), so no node takes a held recipient, and the sweeper does
not queue jobs for one. A delivery already in progress when a message is
held finishes: what was claimed is sent. A held recipient keeps its
retry period: held for longer than it, it fails at its first attempt
after release.
Retry does not interrupt a send. Making a recipient due again while
a job is sending it would send it twice, so the statement that does it
also requires that no delivery job for the message and domain is
executing. If one is, the answer is :being_sent.
Summary
Functions
Cancels the recipients of a scheduled message that were never tried.
Holds the message's recipients that are still to be delivered.
Releases the message's held recipients and queues their delivery.
Makes the message's recipients that wait for a later attempt due now.
Types
@type conflict() ::
:final | :held | :not_held | :being_sent | :due_now | :not_scheduled
@type result() :: {:ok, non_neg_integer()} | {:error, :not_found | {:conflict, conflict()}}
Functions
@spec cancel(Karta.Servers.Server.t(), Ecto.UUID.t(), Karta.Audit.actor(), keyword()) :: result()
Cancels the recipients of a scheduled message that were never tried.
@spec hold(Karta.Servers.Server.t(), Ecto.UUID.t(), Karta.Audit.actor(), keyword()) :: result()
Holds the message's recipients that are still to be delivered.
@spec release(Karta.Servers.Server.t(), Ecto.UUID.t(), Karta.Audit.actor(), keyword()) :: result()
Releases the message's held recipients and queues their delivery.
@spec retry(Karta.Servers.Server.t(), Ecto.UUID.t(), Karta.Audit.actor(), keyword()) :: result()
Makes the message's recipients that wait for a later attempt due now.