Skip to content

Commit

Permalink
facebook: fix rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Nov 14, 2023
1 parent 17d2f38 commit a30afef
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions automon/integrations/facebook/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, url: str = None):
self._visible = None

self._browser = None
self.rate_limit_wait_seconds = random.choice(range(0, 300))
self.rate_limit_wait_seconds = random.choice(range(0, 60))

@property
def content_unavailable(self):
Expand Down Expand Up @@ -469,12 +469,12 @@ def get_with_rate_limiter(
result = self.get(url=url)

if self.rate_limited():
Sleeper.seconds(seconds=self.rate_limit_wait_seconds)
self.rate_limit_increase()
Sleeper.seconds(seconds=self.rate_limit_wait_seconds)
result = False
else:
self.rate_limit_decrease()
log.info(f'{result}')
self.rate_limit_decrease()
self.screenshot_success()
return result

Expand All @@ -484,9 +484,9 @@ def get_with_rate_limiter(
self.screenshot_error()
return result

def rate_limit_decrease(self, multiplier: int = 0.4):
def rate_limit_decrease(self, multiplier: int = 0.5):
before = self.rate_limit_wait_seconds
self.rate_limit_wait_seconds = round(self.rate_limit_wait_seconds * 0.4)
self.rate_limit_wait_seconds = int(self.rate_limit_wait_seconds * 0.4)

log.info(str(dict(
before=before,
Expand All @@ -495,9 +495,9 @@ def rate_limit_decrease(self, multiplier: int = 0.4):
)))
return self.rate_limit_wait_seconds

def rate_limit_increase(self, multiplier: int = 2):
def rate_limit_increase(self, multiplier: int = 1.5):
before = self.rate_limit_wait_seconds
self.rate_limit_wait_seconds = self.rate_limit_wait_seconds * multiplier
self.rate_limit_wait_seconds = int(self.rate_limit_wait_seconds * multiplier)

log.info(str(dict(
before=before,
Expand Down

0 comments on commit a30afef

Please sign in to comment.