elm.ords.services.usage.TimeBoundedUsageTracker
- class TimeBoundedUsageTracker(max_seconds=70)[source]
Bases:
object
Track usage of a resource over time.
This class wraps a double-ended queue, and any inputs older than a certain time are dropped. Those values are also subtracted from the running total.
References
https://stackoverflow.com/questions/51485656/efficient-time-bound-queue-in-python
- Parameters:
max_seconds (int, optional) – Maximum age in seconds of an element before it is dropped from consideration. By default,
65
.
Methods
add
(value)Add a value to track.
Attributes
Total value of all entries younger than max_seconds