Mercurial > templog
changeset 261:c3600a9fa747
merge long polling
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 09 Jun 2015 23:39:22 +0800 |
parents | 6fb9d5f654ff (current diff) 03e540c3ec24 (diff) |
children | ef3a75128116 |
files | |
diffstat | 5 files changed, 21 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/web/config.py Tue Jun 09 23:37:49 2015 +0800 +++ b/web/config.py Tue Jun 09 23:39:22 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 23:37:49 2015 +0800 +++ b/web/log.py Tue Jun 09 23:39:22 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 23:37:49 2015 +0800 +++ b/web/settings.py Tue Jun 09 23:39:22 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-uwsgi.ini Tue Jun 09 23:37:49 2015 +0800 +++ b/web/templog-uwsgi.ini Tue Jun 09 23:39:22 2015 +0800 @@ -13,3 +13,8 @@ # for client certificates. default limit is 4096, not sufficient buffer-size=20000 + +user = matt +group = matt + +chdir = /home/matt/templog/web
--- a/web/templog.py Tue Jun 09 23:37:49 2015 +0800 +++ b/web/templog.py Tue Jun 09 23:39:22 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>')