Method RecordSpendAsync
- Namespace
- MailFathom.Application.Emails.AttachmentText.Limits
- Assembly
- MailFathom.Application.dll
RecordSpendAsync(IPersistenceSession, DateTimeOffset, AttachmentDerivationStep, IReadOnlyCollection<UserId>, long, CancellationToken)
Adds what reading one message consumed, once to the period and in full to each user it is charged to.
Task RecordSpendAsync(IPersistenceSession session, DateTimeOffset periodStart, AttachmentDerivationStep derivationStep, IReadOnlyCollection<UserId> users, long unitCount, CancellationToken cancellationToken)
Parameters
sessionIPersistenceSessionThe session whose transaction this write joins.
periodStartDateTimeOffsetThe period's start, as the budget places it.
derivationStepAttachmentDerivationStepThe step the units belong to.
usersIReadOnlyCollection<UserId>The users the reading is charged to, which is empty for a mailbox assigned to nobody.
unitCountlongWhat the work consumed, in that step's own unit.
cancellationTokenCancellationTokenPropagates caller cancellation.
Returns
- Task
A task that completes when every increment has been issued inside the caller's transaction.
Remarks
One call rather than one per user, because the deployment's own figure is charged here too and charging it from a loop would multiply it by however many people share the mailbox. A reading charged to nobody still moves the deployment's figure, so a mailbox with no assigned user is bounded by the deployment's ceiling rather than by nothing at all.
Written inside the transaction that commits the readings the work produced, so the two are one durable fact: a crash between them cannot leave readings nothing was charged for, or a charge for readings that were never stored. Each increment is expressed as an increment rather than as a read followed by a write, so two account runs charging one period add to each other instead of overwriting one another's total.
Exceptions
- ArgumentNullException
Thrown when
sessionorusersis null.- ArgumentOutOfRangeException
Thrown when the count is negative.