mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 11:41:08 -03:30
fix sliding window calculation
This commit is contained in:
committed by
Ryan Petrello
parent
3f5e2a3cd3
commit
d58df0f34a
@@ -36,16 +36,18 @@ class FixedSlidingWindow():
|
|||||||
self.buckets = dict()
|
self.buckets = dict()
|
||||||
self.start_time = start_time or now_seconds()
|
self.start_time = start_time or now_seconds()
|
||||||
|
|
||||||
def cleanup(self, now_bucket=now_seconds()):
|
def cleanup(self, now_bucket=None):
|
||||||
if self.start_time + 60 >= now_bucket:
|
now_bucket = now_bucket or now_seconds()
|
||||||
self.start_time = now_bucket - 60 + 1
|
if self.start_time + 60 <= now_bucket:
|
||||||
|
self.start_time = now_bucket + 60 + 1
|
||||||
|
|
||||||
# Delete old entries
|
# Delete old entries
|
||||||
for k,v in self.buckets.items():
|
for k in list(self.buckets.keys()):
|
||||||
if k < self.start_time:
|
if k < self.start_time:
|
||||||
del self.buckets[k]
|
del self.buckets[k]
|
||||||
|
|
||||||
def record(self, ts=datetime.datetime.now()):
|
def record(self, ts=None):
|
||||||
|
ts = ts or datetime.datetime.now()
|
||||||
now_bucket = int((ts - datetime.datetime(1970,1,1)).total_seconds())
|
now_bucket = int((ts - datetime.datetime(1970,1,1)).total_seconds())
|
||||||
|
|
||||||
val = self.buckets.get(now_bucket, 0)
|
val = self.buckets.get(now_bucket, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user