mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 09:14:30 +00:00
Implement more request handlers in Tornado #3
This commit is contained in:
@@ -15,9 +15,7 @@ from server.handlers.pagetemplate import PageTemplateHandler
|
||||
|
||||
|
||||
# Provides the public-facing web server.
|
||||
# TODO alerts API
|
||||
# TODO lookup APIs
|
||||
# TODO post spot API
|
||||
# TODO test lookups
|
||||
# TODO SSE API responses
|
||||
# TODO clean_up_sse_queues
|
||||
# TODO page & API access counters - how to do from a subclass handler? e.g.
|
||||
@@ -60,14 +58,14 @@ class WebServer:
|
||||
app = tornado.web.Application([
|
||||
# Routes for API calls
|
||||
(r"/api/v1/spots", APISpotsHandler, {"spots": self.spots}),
|
||||
(r"/api/v1/alerts", APIAlertsHandler),
|
||||
(r"/api/v1/spots/stream", APISpotsStreamHandler),
|
||||
(r"/api/v1/alerts/stream", APIAlertsStreamHandler),
|
||||
(r"/api/v1/alerts", APIAlertsHandler, {"alerts": self.alerts}),
|
||||
(r"/api/v1/spots/stream", APISpotsStreamHandler), # todo provide queues?
|
||||
(r"/api/v1/alerts/stream", APIAlertsStreamHandler), # todo provide queues?
|
||||
(r"/api/v1/options", APIOptionsHandler, {"status_data": self.status_data}),
|
||||
(r"/api/v1/status", APIStatusHandler, {"status_data": self.status_data}),
|
||||
(r"/api/v1/lookup/call", APILookupCallHandler),
|
||||
(r"/api/v1/lookup/sigref", APILookupSIGRefHandler),
|
||||
(r"/api/v1/spot", APISpotHandler),
|
||||
(r"/api/v1/spot", APISpotHandler, {"spots": self.spots}),
|
||||
# Routes for templated pages
|
||||
(r"/", PageTemplateHandler, {"template_name": "spots"}),
|
||||
(r"/map", PageTemplateHandler, {"template_name": "map"}),
|
||||
@@ -87,7 +85,33 @@ class WebServer:
|
||||
app.listen(self.port)
|
||||
await self.shutdown_event.wait()
|
||||
|
||||
# Internal method called when a new spot is added to the system. This is used to ping any SSE clients that are
|
||||
# awaiting a server-sent message with new spots.
|
||||
def notify_new_spot(self, spot):
|
||||
# todo
|
||||
# for queue in self.sse_spot_queues:
|
||||
# try:
|
||||
# queue.put(spot)
|
||||
# except:
|
||||
# # Cleanup thread was probably deleting the queue, that's fine
|
||||
# pass
|
||||
pass
|
||||
|
||||
# Internal method called when a new alert is added to the system. This is used to ping any SSE clients that are
|
||||
# awaiting a server-sent message with new spots.
|
||||
def notify_new_alert(self, alert):
|
||||
# todo
|
||||
# for queue in self.sse_alert_queues:
|
||||
# try:
|
||||
# queue.put(alert)
|
||||
# except:
|
||||
# # Cleanup thread was probably deleting the queue, that's fine
|
||||
# pass
|
||||
pass
|
||||
|
||||
# Clean up any SSE queues that are growing too large; probably their client disconnected.
|
||||
def clean_up_sse_queues(self):
|
||||
# todo
|
||||
# self.sse_spot_queues = [q for q in self.sse_spot_queues if not q.full()]
|
||||
# self.sse_alert_queues = [q for q in self.sse_alert_queues if not q.full()]
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user