Karta. Messaging. Inbound
(Karta v1.0.0)
Applies the events an agent sends (postduif-protocol.md section 3):
exactly once in effect, however often and in whatever order they arrive.
One events frame is applied in one transaction with the connector's
row locked, and the position the agent may delete up to
(acked_event_seq) is committed in that same transaction; only then is
it acknowledged. Three things make a repeat harmless:
- an item at or below
acked_event_seqis skipped; - a message is unique per connector and
provider_id, a status per message and journal position (source_event_id), so an item applied before (a frame resent after a lost ack, or after a new journal) is recognised and does nothing, and raises no second webhook; - the position moves only over a contiguous run: items that arrive ahead of a gap are applied but not acknowledged, and the agent sends them again after the gap is filled.
An item that can never succeed (malformed, an unknown kind) is
rejected in the ack and counts as consumed.
History imported when a number is first linked (backfill: true) is
stored, not announced. A message that arrives with media finds the media
the agent uploaded before the event (Karta.Messaging.MediaStore).
Summary
Functions
Applies the raw items of an events frame for the connector. ahead is
the set of positions this connection applied above a gap earlier (the
session keeps it): when the gap is filled the position moves over them
too, and they come back in the outcome for the next call.
Types
@type outcome() :: {:ok, %{upto_seq: non_neg_integer(), rejected: [map()], ahead: MapSet.t(integer())}} | {:error, :revoked}
Functions
@spec process(Ecto.UUID.t(), [term()], MapSet.t(integer())) :: outcome()
Applies the raw items of an events frame for the connector. ahead is
the set of positions this connection applied above a gap earlier (the
session keeps it): when the gap is filled the position moves over them
too, and they come back in the outcome for the next call.