Interface IOutgoingEmailStore
- Namespace
- MailFathom.Application.Mail.Delivery
- Assembly
- MailFathom.Application.dll
Keeps the durable record of every message MailFathom has been asked to send.
public interface IOutgoingEmailStore
Remarks
The idempotency identity is the sending account and the authoring act together, and it is enforced by a unique constraint rather than by this contract declining to write. Two callers asking for the same send at the same moment both reach the database, and one of them loses there; a check-then-insert would let both through the window between the two statements, and unlike a duplicated local row a duplicated delivery cannot be withdrawn.
Writes take the caller's session, because the record and the MIME it points at are one write: a record whose message was not stored has nothing to transmit, and a message stored under no record is bytes nothing will ever read. Reads take none, because a read joins no transaction.
Two writes are the exception to both, and are the two this port hands no session. A claim selects and stamps in one statement so two workers claiming at the same moment take different records rather than the same one, which no session-scoped read followed by a write can promise, and its transaction ends with the claim because the attempt that follows reaches a submission server. The sweep that stamps the records a stopped process left mid-transmission is the other: it is one set-based write over rows nobody holds, and joining a caller's transaction would hold them for as long as that caller ran.
Every write an attempt makes afterwards names the lease it holds and is refused when the record has moved on to a later attempt. That is the second half of what keeps one send in one pair of hands: the first is that an attempt is cancelled before its lease can expire underneath it.
Methods
- AdvanceAsync(IPersistenceSession, OutgoingEmailLease, OutgoingEmailId, OutgoingEmailStage, int?, CancellationToken)
Moves the record to a terminal stage, recording the reply the server answered the transmission with.
- ClaimAsync(OutgoingEmailClaimRequest, CancellationToken)
Takes up to a batch of the account's due sends and leases each of them to one attempt.
- CountOutstandingByStageAsync(MailAccountId, CancellationToken)
Counts how many of the account's sends stand at each stage nothing has finished with.
- DeferAsync(IPersistenceSession, OutgoingEmailLease, OutgoingEmailId, DateTimeOffset, MailFathomErrorCode?, CancellationToken)
Gives a held record back after a failure that can clear, claimable again once the instant named has passed.
- FindAsync(OutgoingEmailId, CancellationToken)
Reads one record back by the identifier everything after the first write refers to it by.
- MarkUnknownOutcomesAsync(MailAccountId, CancellationToken)
Marks the account's sends whose transmission was never answered, so an operator reads why they are stuck.
- OpenAsync(IPersistenceSession, OutgoingEmailRequest, OutgoingEmailPrincipal, long, CancellationToken)
Writes the intent down, or reads back the record that already holds this idempotency identity.
- ReadOutstandingAsync(MailAccountId, int, CancellationToken)
Reads the sends of one account that have not reached a terminal stage.
- RecordFailureAsync(IPersistenceSession, OutgoingEmailLease, OutgoingEmailId, MailFathomErrorCode, CancellationToken)
Records the failure the last attempt ended in, without moving the stage.
- RecordRecipientOutcomesAsync(IPersistenceSession, OutgoingEmailLease, OutgoingEmailId, IReadOnlyList<OutgoingRecipientOutcome>, CancellationToken)
Records what one attempt settled about the recipients it offered.
- RecordTransmissionBegunAsync(IPersistenceSession, OutgoingEmailLease, OutgoingEmailId, CancellationToken)
Moves the record to TransmissionBegun.
- ReleaseAsync(IPersistenceSession, OutgoingEmailLease, OutgoingEmailId, CancellationToken)
Gives a held record back unfinished, so it is claimable again at once and holds no attempt against it.