SSE updates every 5 seconds is probably fine, we don't really need every second. #3

This commit is contained in:
Ian Renton
2025-12-24 08:57:38 +00:00
parent e8ca488001
commit 2fead92dc5
2 changed files with 10 additions and 4 deletions

View File

@@ -10,6 +10,9 @@ import tornado_eventsource.handler
from core.prometheus_metrics_handler import api_requests_counter
from core.utils import serialize_everything
SSE_HANDLER_MAX_QUEUE_SIZE = 1000
SSE_HANDLER_QUEUE_CHECK_INTERVAL = 5000
# API request handler for /api/v1/spots
class APISpotsHandler(tornado.web.RequestHandler):
@@ -65,11 +68,11 @@ class APISpotsStreamHandler(tornado_eventsource.handler.EventSourceHandler):
self.query_params = {k: v[0].decode("utf-8") for k, v in self.request.arguments.items()}
# Create a spot queue and add it to the web server's list. The web server will fill this when spots arrive
self.spot_queue = Queue(maxsize=1000)
self.spot_queue = Queue(maxsize=SSE_HANDLER_MAX_QUEUE_SIZE)
self.sse_spot_queues.append(self.spot_queue)
# Set up a timed callback to check if anything is in the queue
self.heartbeat = tornado.ioloop.PeriodicCallback(self._callback, 1000)
self.heartbeat = tornado.ioloop.PeriodicCallback(self._callback, SSE_HANDLER_QUEUE_CHECK_INTERVAL)
self.heartbeat.start()
except Exception as e: