Skip to content

Commit

Permalink
Merge branch 'develop': v 1.2.4. Update response timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mahenzon committed Aug 4, 2019
2 parents cfd2a04 + e84119e commit 04fa69e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aioalice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())


__version__ = '1.2.3'
__version__ = '1.2.4'
17 changes: 9 additions & 8 deletions aioalice/dispatcher/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
ERROR_RESPONSE_KEY = 'ALICE_ERROR_RESPONSE'

DEFAULT_ERROR_RESPONSE_TEXT = 'Server error. Developer has to check logs.'
# Max time to response to API is 1.5s
# with server on Aruba (Italy) 1.2s is a critical timeout for whole processing
# Max time to response to API is 3s: https://yandex.ru/blog/dialogs/bolshe-vremeni-na-otvet-time-out-3-sekundy
# with server on Aruba (Italy) whole processing (with networking) takes about 0.3s
# NOTE that this timeout can help only if using non-blocking IO
# in e.g use asyncio.sleep instead of time.sleep, aiohttp instead of requests, etc
# Whole processing usually takes from 0.0004 до 0.001 (depends on system IO),
# but Yandex starts countdown as user asks a question, request processing takes some time
RESPONSE_TIMEOUT = 1.2
# but Yandex starts countdown the moment when user asks a question
# networking takes some time
RESPONSE_TIMEOUT = 2.7


class WebhookRequestHandler(web.View):
Expand Down Expand Up @@ -63,9 +64,9 @@ async def parse_request(self):

async def process_request(self, request):
"""
You have to respond in less than 1.5 seconds to webhook.
You have to respond in less than 3 seconds to webhook.
So... If you process longer than 1.2 (RESPONSE_TIMEOUT) seconds
So... If you process longer than 2.7 (RESPONSE_TIMEOUT) seconds
webhook automatically respond with FALLBACK VALUE (ERROR_RESPONSE_KEY)
:param request:
Expand Down Expand Up @@ -105,7 +106,7 @@ def warn_slow_process(self, request):

def slow_request_processor(task):
"""
Handle response after 1.2 sec (RESPONSE_TIMEOUT)
Handle response after 2.7 sec (RESPONSE_TIMEOUT)
:param task:
:return:
Expand All @@ -131,7 +132,7 @@ def slow_request_processor(task):
def default_error_response(self, alice_request):
"""
Default error response will be called on timeout
if processing of the request will take more than 1.2s (RESPONSE_TIMEOUT)
if processing of the request will take more than 2.7s (RESPONSE_TIMEOUT)
:param result: dict or AliceRequest
:return: AliceResponse
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if sys.version_info < MINIMAL_PY_VERSION:
raise RuntimeError('aioAlice works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION))))

__version__ = '1.2.3'
__version__ = '1.2.4'


def get_description():
Expand Down

0 comments on commit 04fa69e

Please sign in to comment.