summaryrefslogtreecommitdiff
path: root/lorry-controller-webapp
diff options
context:
space:
mode:
Diffstat (limited to 'lorry-controller-webapp')
-rwxr-xr-xlorry-controller-webapp43
1 files changed, 39 insertions, 4 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp
index 6acbac0..3963853 100755
--- a/lorry-controller-webapp
+++ b/lorry-controller-webapp
@@ -26,6 +26,27 @@ import cliapp
from flup.server.fcgi import WSGIServer
+STATUS_HTML_TEMPLATE = '''
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Lorry Controller status</title>
+ </head>
+ <body>
+ <blockquote>{quote}</blockquote>
+
+ <h1>Status of Lorry Controller</h1>
+
+ <p>Running queue: {running-queue}.</p>
+
+ <hr>
+
+ <p>Updated: {timestamp}</p>
+ </body>
+</html>
+'''
+
+
class StateDB(object):
'''A wrapper around raw Sqlite for STATEDB.'''
@@ -75,7 +96,8 @@ class LorryControllerRoute(object):
'''
- def __init__(self, statedb):
+ def __init__(self, app_settings, statedb):
+ self.app_settings = app_settings
self.statedb = statedb
def run(self, **kwargs):
@@ -94,10 +116,17 @@ class Status(LorryControllerRoute):
"I'm giving her all she's got, Captain!",
]
import random
- return {
- 'quote': '%s\n' % random.choice(quotes),
+ status = {
+ 'quote': '%s' % random.choice(quotes),
'running-queue': self.statedb.get_running_queue(),
+ 'timestamp': time.strftime('%Y-%m-%d %H:%M:%S'),
}
+ self.write_static_status_page(status)
+ return status
+
+ def write_static_status_page(self, status):
+ with open(self.app_settings['status-html'], 'w') as f:
+ f.write(STATUS_HTML_TEMPLATE.format(**status))
class StartQueue(LorryControllerRoute):
@@ -128,6 +157,12 @@ class WEBAPP(cliapp.Application):
'use FILE as the state database',
metavar='FILE')
+ self.settings.string(
+ ['status-html'],
+ 'write a static HTML page to FILE to describe overall status',
+ metavar='FILE',
+ default='/dev/null')
+
self.settings.boolean(
['wsgi'],
'run in wsgi mode (default is debug mode, for development)')
@@ -172,7 +207,7 @@ class WEBAPP(cliapp.Application):
webapp = bottle.Bottle()
for route_class in self.find_routes():
- route = route_class(statedb)
+ route = route_class(self.settings, statedb)
webapp.route(
path=route.path,
method=route.http_method,