Skip to content

Commit

Permalink
facebook: fix rate limit increase when WAIT_BETWEEN_RETRIES is zero
Browse files Browse the repository at this point in the history
zero times anything is zero.

I remembered that from math school.
  • Loading branch information
naisanzaa committed Nov 9, 2024
1 parent af8a25e commit d63ffa7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion automon/integrations/facebook/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit d63ffa7

Please sign in to comment.