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, 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.
Constructors
- EmbeddingSpendGate(IEmbeddingSpendLedger, EmbeddingSpendBudget, TimeProvider)
Initializes a new gate over one deployment's budget.
Methods
- ReadCurrentPeriodAsync(CancellationToken)
Reads where the current period stands, which is what a run consults before it starts spending.
- RecordSpendAsync(IPersistenceSession, long, CancellationToken)
Charges one provider call to the period it happened in.