Interface SmsCostLedgerRepository


public interface SmsCostLedgerRepository
Port that keeps the ledger of what text messages cost, in the database so that a restart cannot reset a budget.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Deletes the entries older than an instant.
    boolean
    tryRecord(Instant sentAt, String country, long costMicros, SmsSpendCap windowCap, SmsSpendCap dailyCap)
    Records a message only when it keeps the spend within both caps, atomically: of concurrent callers, the ones whose messages would together exceed a cap are refused, so a budget is never overshot.
  • Method Details

    • tryRecord

      boolean tryRecord(Instant sentAt, String country, long costMicros, SmsSpendCap windowCap, SmsSpendCap dailyCap)
      Records a message only when it keeps the spend within both caps, atomically: of concurrent callers, the ones whose messages would together exceed a cap are refused, so a budget is never overshot. Nothing is recorded for a refused message. It runs in the caller's transaction and the reservation is kept only if that transaction commits.
      Parameters:
      sentAt - instant of the message.
      country - ISO 3166-1 alpha-2 code of the destination country.
      costMicros - cost of the message, in millionths of the budget currency.
      windowCap - cap of the short window that ends at sentAt.
      dailyCap - cap of the day that ends at sentAt.
      Returns:
      true when the message was recorded; false when it would exceed a cap.
    • deleteOlderThan

      int deleteOlderThan(Instant before)
      Deletes the entries older than an instant.
      Parameters:
      before - instant before which entries are no longer needed.
      Returns:
      the number of deleted entries.