DVMeters class

Records usage, places it in its period, and applies limits.

Constructors

DVMeters({required DVMeterStore store, DateTime clock()?, DVBillingPeriodResolver? periods, DVMeterLimitResolver? limits, DVMeterThresholdHandler? onThreshold, Duration grace = Duration.zero, DVLogger? logger})

Properties

grace → Duration
The deployment's grace for late records, when a meter declares none.
final
hashCode → int
The hash code for this object.
no setterinherited
limits → DVMeterLimitResolver?
final
now → DateTime
The time these meters consider current, in UTC.
no setter
onThreshold → DVMeterThresholdHandler?
Called for each notification threshold a recording crosses. This is the seam Notifications sends through.
final
periods → DVBillingPeriodResolver?
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
store → DVMeterStore
final

Methods

admitLevel(DVLevelLimit level, {num adding = 1}) → Future<DVMeterOutcome>
Checks level for the current tenant, as if adding more existed.
admits(DVMeterDefinition meter, num amount) → Future<DVMeterOutcome>
Whether recording amount against meter for the current tenant would be admitted, without recording anything.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
record(DVMeterDefinition meter, num amount, {String? idempotencyKey, DateTime? at}) → Future<DVMeterOutcome>
Records amount against meter for the current tenant.
toString() → String
A string representation of this object.
inherited
usage(DVMeterDefinition meter, {required String tenant, DVMeterPeriod? period}) → Future<num>
Usage of meter by tenant in period, defaulting to the open one.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

current → DVMeters
no setter
currentIdempotencyKey → String?
no setter

Static Methods

configure(DVMeters meters) → void
Sets the meters DVMeterDefinition.record records through.
unconfigure() → void
withIdempotencyKey<R>(String key, R body()) → R
Runs body with key as the idempotency key for recordings that do not pass one: the request id for a backend call, the job id for a job, so a retry of either counts once however many attempts it took.