First attempt at SSE backend #3

This commit is contained in:
Ian Renton
2025-12-22 13:02:11 +00:00
parent befaceb2f5
commit fd2986f310
4 changed files with 37 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ from queue import Queue
from threading import Thread
import bottle
import gevent
import pytz
from bottle import run, request, response, template
@@ -73,7 +74,7 @@ class WebServer:
def run(self):
logging.info("Starting web server on port " + str(self.port) + "...")
self.status = "Waiting"
run(host='localhost', port=self.port)
run(host='localhost', port=self.port, server="gevent")
# Serve the JSON API /spots endpoint
def serve_spots_api(self):
@@ -116,8 +117,11 @@ class WebServer:
spot_queue = Queue(maxsize=100)
self.sse_spot_queues.append(spot_queue)
while True:
spot = spot_queue.get()
yield 'data: ' + json.dumps(spot, default=serialize_everything) + '\n\n'
if spot_queue.empty():
gevent.sleep(1)
else:
spot = spot_queue.get()
yield 'data: ' + json.dumps(spot, default=serialize_everything) + '\n\n'
# Serve the SSE JSON API /alerts/stream endpoint
@@ -129,8 +133,11 @@ class WebServer:
alert_queue = Queue(maxsize=100)
self.sse_alert_queues.append(alert_queue)
while True:
alert = alert_queue.get()
yield 'data: ' + json.dumps(alert, default=serialize_everything) + '\n\n'
if alert_queue.empty():
gevent.sleep(1)
else:
alert = alert_queue.get()
yield 'data: ' + json.dumps(alert, default=serialize_everything) + '\n\n'
# Look up data for a callsign
def serve_call_lookup_api(self):