Exemplo n.º 1
0
def enable_rate_limit(request):
    if request.authz.logged_in:
        return
    limit = settings.API_RATE_LIMIT * settings.API_RATE_WINDOW
    request.rate_limit = get_rate_limit(_get_remote_ip(),
                                        limit=limit,
                                        interval=settings.API_RATE_WINDOW,
                                        unit=60)
    if not request.rate_limit.check():
        raise TooManyRequests("Rate limit exceeded.")
Exemplo n.º 2
0
def queue_worker(timeout=5):
    """The main event loop for the Aleph backend."""
    hourly = get_rate_limit('hourly', unit=3600, interval=1, limit=1)
    daily = get_rate_limit('daily', unit=3600, interval=24, limit=1)
    log.info("Worker: %s", kv)
    while True:
        if hourly.check():
            hourly.update()
            hourly_tasks()

        if daily.check():
            daily.update()
            daily_tasks()

        queue, payload, context = get_next_task(timeout=timeout)
        if queue is None:
            continue
        handle_task(queue, payload, context)
        db.session.remove()
Exemplo n.º 3
0
 def boot(self):
     self.hourly = get_rate_limit('hourly', unit=3600, interval=1, limit=1)
     self.daily = get_rate_limit('daily', unit=3600, interval=24, limit=1)
Exemplo n.º 4
0
 def boot(self):
     self.often = get_rate_limit("often", unit=300, interval=1, limit=1)
     self.hourly = get_rate_limit("hourly", unit=3600, interval=1, limit=1)
     self.daily = get_rate_limit("daily", unit=3600, interval=24, limit=1)