From 86e72edfc15fff496d8bdc06f2f360495589d1b8 Mon Sep 17 00:00:00 2001 From: Kyle Mahan Date: Sun, 5 Jun 2016 00:10:58 +0000 Subject: [PATCH] set requests-get timeout to fail quickly when a server is unresponsive --- requirements.txt | 2 +- woodwind.ini | 2 +- woodwind/templates/_entry.jinja2 | 1 + woodwind/util.py | 3 +++ woodwind/views.py | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index a0ef340..c934e28 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,7 +27,7 @@ pyquerystring==1.0.2 pytz==2016.4 redis==2.10.5 requests==2.10.0 -rq==0.6.0 +rq==0.5.6 sgmllib3k==1.0.0 six==1.10.0 SQLAlchemy==1.0.13 diff --git a/woodwind.ini b/woodwind.ini index 52a59e2..18017fa 100644 --- a/woodwind.ini +++ b/woodwind.ini @@ -13,5 +13,5 @@ module=woodwind.wsgi import=timers #attach-daemon=venv/bin/rqworker high -attach-daemon=venv/bin/rqworker high low attach-daemon=venv/bin/python -m woodwind.websocket_server +attach-daemon=venv/bin/rqworker high low diff --git a/woodwind/templates/_entry.jinja2 b/woodwind/templates/_entry.jinja2 index abd3f57..6f8d27d 100644 --- a/woodwind/templates/_entry.jinja2 +++ b/woodwind/templates/_entry.jinja2 @@ -85,6 +85,7 @@ {{ entry.published | relative_time }} + diff --git a/woodwind/util.py b/woodwind/util.py index 2acd188..df2b992 100644 --- a/woodwind/util.py +++ b/woodwind/util.py @@ -40,6 +40,9 @@ def requests_get(url, **kwargs): if 'Last-Modified' in lastresp.headers: headers['If-Modified-Since'] = lastresp.headers['Last-Modified'] + if 'timeout' not in kwargs: + kwargs['timeout'] = (9.1, 30) + current_app.logger.debug('fetching %s with args %s', url, kwargs) resp = requests.get(url, **kwargs) diff --git a/woodwind/views.py b/woodwind/views.py index 457d63e..517ed16 100644 --- a/woodwind/views.py +++ b/woodwind/views.py @@ -355,7 +355,7 @@ def update_micropub_syndicate_to(): resp, resp.text) return - flask.current_app.logger.debug('syndicate-to response: {}, {}', + flask.current_app.logger.debug('syndicate-to response: %s %s', resp, resp.text) content_type = resp.headers['content-type']