mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Apply SSE Spot Provider patch by Steven M1SDH
This commit is contained in:
@@ -34,11 +34,19 @@ class SSESpotProvider(SpotProvider):
|
|||||||
if self.thread:
|
if self.thread:
|
||||||
self.thread.join()
|
self.thread.join()
|
||||||
|
|
||||||
|
def _on_open(self):
|
||||||
|
self.status = "Waiting for Data"
|
||||||
|
|
||||||
|
def _on_error(self):
|
||||||
|
self.status = "Connecting"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while not self.stopped:
|
while not self.stopped:
|
||||||
try:
|
try:
|
||||||
logging.debug("Connecting to " + self.name + " spot API...")
|
logging.debug("Connecting to " + self.name + " spot API...")
|
||||||
with EventSource(self.url, headers=HTTP_HEADERS, latest_event_id=self.last_event_id, timeout=30) as event_source:
|
self.status = "Connecting"
|
||||||
|
with EventSource(self.url, headers=HTTP_HEADERS, latest_event_id=self.last_event_id, timeout=30,
|
||||||
|
on_open=self._on_open, on_error=self._on_error) as event_source:
|
||||||
self.event_source = event_source
|
self.event_source = event_source
|
||||||
for event in self.event_source:
|
for event in self.event_source:
|
||||||
if event.type == 'message':
|
if event.type == 'message':
|
||||||
@@ -58,6 +66,8 @@ class SSESpotProvider(SpotProvider):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.status = "Error"
|
self.status = "Error"
|
||||||
logging.exception("Exception in SSE Spot Provider (" + self.name + ")")
|
logging.exception("Exception in SSE Spot Provider (" + self.name + ")")
|
||||||
|
else:
|
||||||
|
self.status = "Disconnected"
|
||||||
sleep(5) # Wait before trying to reconnect
|
sleep(5) # Wait before trying to reconnect
|
||||||
|
|
||||||
# Convert an SSE message received from the API into a spot. The whole message data is provided here so the subclass
|
# Convert an SSE message received from the API into a spot. The whole message data is provided here so the subclass
|
||||||
|
|||||||
Reference in New Issue
Block a user