Mercurial > templog
changeset 559:d563e14da813
fix server side long polling
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 09 Jun 2015 23:29:11 +0800 |
parents | 9f659ece4e63 |
children | 18e6e830ca26 |
files | web/config.py web/log.py web/settings.py web/templog.py |
diffstat | 4 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/web/config.py Tue Jun 09 21:22:10 2015 +0800 +++ b/web/config.py Tue Jun 09 23:29:11 2015 +0800 @@ -56,6 +56,8 @@ # 1 hour CSRF_TIMEOUT = 3600 +LONG_POLL_TIMEOUT = 500 + try: from localconfig import * except ImportError:
--- a/web/log.py Tue Jun 09 21:22:10 2015 +0800 +++ b/web/log.py Tue Jun 09 23:29:11 2015 +0800 @@ -247,8 +247,8 @@ tick_secs = int(entries['tick_secs']) return val_ticks + float(val_rem) * tick_secs / tick_wake -def write_current_params(current_params): - fridge_settings.update(current_params) +def write_current_params(current_params, current_epoch): + fridge_settings.update(current_params, current_epoch) def read_current_params(): params, epochtag = fridge_settings.get()
--- a/web/settings.py Tue Jun 09 21:22:10 2015 +0800 +++ b/web/settings.py Tue Jun 09 23:29:11 2015 +0800 @@ -2,6 +2,9 @@ import fcntl import hashlib +import binascii +import os + class Settings(object): RAND_SIZE = 15 # 120 bits @@ -22,7 +25,7 @@ self.epoch = None self.tag = None - self.update(self, None, 'startepoch') + self.update(None, 'startepoch') def wait(self, epoch_tag = None, timeout = None): """ returns false if the timeout was hit """
--- a/web/templog.py Tue Jun 09 21:22:10 2015 +0800 +++ b/web/templog.py Tue Jun 09 23:29:11 2015 +0800 @@ -163,12 +163,16 @@ req_etag = request.headers.get('etag', None) if req_etag: # wait for it to change - if not log.fridge_settings.wait(req_etag, timeout=LONG_POLL_TIMEOUT): - response.status = 304 - return "Nothing happened" + # XXX this is meant to return True if it has been woken up + # but it isn't working. Instead compare epochtag below. + log.fridge_settings.wait(req_etag, timeout=config.LONG_POLL_TIMEOUT) + + contents, epoch_tag = log.fridge_settings.get() + if epoch_tag == req_etag: + response.status = 304 + return "Nothing happened" response.set_header('Content-Type', 'application/json') - contents, epoch_tag = client_settings.get() return json.dumps({'params': contents, 'epoch_tag': epoch_tag}) @bottle.get('/<filename:re:.*\.js>')