comparison web/templog.py @ 258:03e540c3ec24

fix server side long polling
author Matt Johnston <matt@ucc.asn.au>
date Tue, 09 Jun 2015 23:29:11 +0800
parents 8ef52f27cf95
children 205809a8872f 9be8464e4295
comparison
equal deleted inserted replaced
257:d0c29436bb63 258:03e540c3ec24
161 def get_settings(): 161 def get_settings():
162 response.set_header('Cache-Control', 'no-cache') 162 response.set_header('Cache-Control', 'no-cache')
163 req_etag = request.headers.get('etag', None) 163 req_etag = request.headers.get('etag', None)
164 if req_etag: 164 if req_etag:
165 # wait for it to change 165 # wait for it to change
166 if not log.fridge_settings.wait(req_etag, timeout=LONG_POLL_TIMEOUT): 166 # XXX this is meant to return True if it has been woken up
167 response.status = 304 167 # but it isn't working. Instead compare epochtag below.
168 return "Nothing happened" 168 log.fridge_settings.wait(req_etag, timeout=config.LONG_POLL_TIMEOUT)
169
170 contents, epoch_tag = log.fridge_settings.get()
171 if epoch_tag == req_etag:
172 response.status = 304
173 return "Nothing happened"
169 174
170 response.set_header('Content-Type', 'application/json') 175 response.set_header('Content-Type', 'application/json')
171 contents, epoch_tag = client_settings.get()
172 return json.dumps({'params': contents, 'epoch_tag': epoch_tag}) 176 return json.dumps({'params': contents, 'epoch_tag': epoch_tag})
173 177
174 @bottle.get('/<filename:re:.*\.js>') 178 @bottle.get('/<filename:re:.*\.js>')
175 def javascripts(filename): 179 def javascripts(filename):
176 response.set_header('Cache-Control', "public, max-age=1296000") 180 response.set_header('Cache-Control', "public, max-age=1296000")