feat(batch): add --batch-limit

This commit is contained in:
Claas Augner 2021-01-19 18:53:53 +01:00
parent 2c5eba14b4
commit 8761af718d
3 changed files with 11 additions and 2 deletions

View file

@ -13,7 +13,7 @@ def get_remote_address():
return ip
def create_app(char_limit=-1, req_limit=-1, ga_id=None, debug=False, frontend_language_source="en", frontend_language_target="en"):
def create_app(char_limit=-1, req_limit=-1, batch_limit=-1, ga_id=None, debug=False, frontend_language_source="en", frontend_language_target="en"):
from app.init import boot
boot()
@ -207,6 +207,11 @@ def create_app(char_limit=-1, req_limit=-1, ga_id=None, debug=False, frontend_la
batch = isinstance(q, list)
if batch and batch_limit != -1:
batch_size = len(q)
if batch_limit < batch_size:
abort(400, description="Invalid request: Request (%d) exceeds text limit (%d)" % (batch_size, batch_limit))
if char_limit != -1:
if batch:
chars = sum([len(text) for text in q])