Table of Contents

Class EmbeddingSpendGate

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

Answers whether embedding may spend right now, and records what it did spend.

public sealed class EmbeddingSpendGate
Inheritance
EmbeddingSpendGate
Inherited Members

Remarks

One type owns both halves because they are one decision: what a period admits is decided by what the same period has been charged, and splitting the question from the answer would let a reader consult one clock and a writer another.

The reading is deliberately cheap and unconditional rather than cached. A period's total is one indexed row per user, the read happens beside a network call that costs orders of magnitude more, and a cached figure would be wrong exactly when it matters — after a restart, or while a second worker is spending against the same period.

Two readings exist because two callers ask different questions, and the mailbox's is the one background work asks. Mail belongs to the account, so a pass holds an account and never a person, while the per-user ceiling still has to mean something: ADR 0014 settles it by counting a shared mailbox in full against every user assigned to it, so work proceeds only while every one of them is under their ceiling, and one call's characters are charged to each. That fan-out lives here rather than in each pass, so the reading and the charge cannot come to disagree about who a mailbox is for.

The deployment's is the other, and it is what an administrative surface asks: it acts for nobody's mail, so where the deployment stands is the only question it can be answered.

The deployment's figure is not the sum of those per-user charges and is never derived from them. Counting a shared mailbox in full against each of its users is what the per-user ceiling means, so the per-user figures add up to more than was sent, and a deployment ceiling read off their sum would stop a mailbox three people share after a third of what the operator declared. The ledger counts what one call sent once, separately.

Constructors

EmbeddingSpendGate(IEmbeddingSpendLedger, IMailAccountAssignments, EmbeddingSpendBudget, TimeProvider)

Initializes a new gate over one deployment's budget.

Methods

ReadCurrentPeriodAsync(CancellationToken)

Reads where the deployment stands in the current period, whatever any one user has spent of it.

ReadCurrentPeriodForAccountAsync(MailAccountId, CancellationToken)

Reads where one mailbox stands in the current period, across every user it is assigned to.

RecordAccountSpendAsync(IPersistenceSession, MailAccountId, long, CancellationToken)

Charges one provider call to the period it happened in and to every user the mailbox is assigned to.