diff --git a/automon/integrations/facebook/groups.py b/automon/integrations/facebook/groups.py index 3959b293..6d765bee 100644 --- a/automon/integrations/facebook/groups.py +++ b/automon/integrations/facebook/groups.py @@ -168,6 +168,7 @@ def average_rate(self): if self.RATE_COUNTER: seconds = round(statistics.mean(self.RATE_COUNTER), 1) minutes = round(seconds / 60, 1) + hours = round(minutes / 60, 1) logger.info(f'total requests={len(self.RATE_COUNTER)} :: {seconds=} :: {minutes=}') return seconds return 0 @@ -452,7 +453,7 @@ def get(self, url: str) -> bool: now = datetime.datetime.now().timestamp() if self.LAST_REQUEST: - self.RATE_COUNTER.append(abs(round(self.LAST_REQUEST - now, 1))) + self.RATE_COUNTER.append(abs(round(self.LAST_REQUEST - now, 1))) else: self.LAST_REQUEST = round(now, 1) @@ -522,6 +523,9 @@ def rate_limit_decrease(self, multiplier: int = 0.75): return after def rate_limit_increase(self, multiplier: int = 2): + if self.WAIT_BETWEEN_RETRIES == 0: + self.WAIT_BETWEEN_RETRIES = random.choice(range(1, 60)) + before = self.WAIT_BETWEEN_RETRIES after = abs(int(self.WAIT_BETWEEN_RETRIES * multiplier))