Nice recursive data cacher

This commit is contained in:
Alexey Lavrenuke 2014-09-11 23:49:34 +04:00
parent dc80758396
commit 2994aa16bc
4 changed files with 13 additions and 3 deletions

View File

@ -18,3 +18,6 @@ class DataCacher(object):
def store(self, data):
for ts, subtree in data.iteritems():
collect_subtree(self.storage, subtree, ts)
def get_all_data(self):
return self.storage

View File

@ -55,7 +55,7 @@ class OnlineReportPlugin(AbstractPlugin, Thread, AggregateResultListener):
def prepare_test(self):
try:
self.server = ReportServer()
self.server = ReportServer(self.cache)
self.server.owner = self
except Exception, ex:
self.log.warning("Failed to start web results server: %s", ex)

View File

@ -29,11 +29,16 @@ class Client(SocketConnection):
Client.CONNECTION = None
class MainHandler(tornado.web.RequestHandler):
cacher = None
def get(self):
self.render("index.jade")
if cacher is not None:
cached_data = cacher.get_all_data()
else:
cached_data = {}
self.render("index.jade", cached_data=cached_data)
class ReportServer(object):
def __init__(self):
def __init__(self, cacher):
router = TornadioRouter(Client)
self.app = tornado.web.Application(
router.apply_routes([(r"/", MainHandler)]),
@ -41,6 +46,7 @@ class ReportServer(object):
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True,
)
MainHandler.cacher = cacher
def serve(self):
def run_server():

View File

@ -7,5 +7,6 @@ html(lang="en")
script(src="static/js/ws.js")
body
h1.title="Yandex.Tank report"
p {{cached_data}}
p My beautiful report
#msg