Table of Contents

Method RecordSpendAsync

Namespace
MailFathom.Application.Emails.Embeddings.Limits
Assembly
MailFathom.Application.dll

RecordSpendAsync(IPersistenceSession, DateTimeOffset, IReadOnlyCollection<UserId>, long, CancellationToken)

Adds what one provider call sent, once to the period and in full to each user it is counted against.

Task RecordSpendAsync(IPersistenceSession session, DateTimeOffset periodStart, IReadOnlyCollection<UserId> users, long inputCharacterCount, CancellationToken cancellationToken)

Parameters

session IPersistenceSession

The session whose transaction this write joins.

periodStart DateTimeOffset

The period's start, as the budget places it.

users IReadOnlyCollection<UserId>

The users the call is charged to, which is empty for a mailbox assigned to nobody.

inputCharacterCount long

The characters the call sent.

cancellationToken CancellationToken

Propagates 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 call 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 vectors the call produced, so the two are one durable fact: a crash between them cannot leave vectors nothing was charged for, or a charge for vectors that were never stored. Each increment is expressed as an increment rather than as a read followed by a write, so two workers spending against one period add to each other instead of overwriting one another's total.

Exceptions

ArgumentNullException

Thrown when session or users is null.

ArgumentOutOfRangeException

Thrown when the count is negative.