mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-26 16:34:43 +03:00
Refactor MQTT (#24010)
* refactor mqtt so that Frigate owns the transport lifecycle instead of delegating it to paho * release the shutdown barrier on worker crash and replay retained publishes the broker never acked * collapse in-flight retained values by topic and release the shutdown barrier from a finally * replay the outage buffer before the publish queue so newer values are not reverted
This commit is contained in:
committed by
Nicolas Mowen
parent
f4cf1e1539
commit
ad04101c76
@@ -18,10 +18,13 @@ SOCKET_REP_REQ = "ipc:///tmp/cache/comms"
|
||||
|
||||
class InterProcessCommunicator(Communicator):
|
||||
def __init__(self) -> None:
|
||||
# bound eagerly so subprocesses starting before start_communicators()
|
||||
# can still connect; their requests queue in zmq until the reader runs
|
||||
self.context = zmq.Context()
|
||||
self.socket = self.context.socket(zmq.REP)
|
||||
self.socket.bind(SOCKET_REP_REQ)
|
||||
self.stop_event: MpEvent = mp.Event()
|
||||
self.reader_thread: threading.Thread | None = None
|
||||
|
||||
def publish(self, topic: str, payload: Any, retain: bool = False) -> None:
|
||||
"""There is no communication back to the processes."""
|
||||
@@ -29,6 +32,8 @@ class InterProcessCommunicator(Communicator):
|
||||
|
||||
def subscribe(self, receiver: Callable) -> None:
|
||||
self._dispatcher = receiver
|
||||
|
||||
def start(self) -> None:
|
||||
self.reader_thread = threading.Thread(target=self.read)
|
||||
self.reader_thread.start()
|
||||
|
||||
@@ -61,7 +66,8 @@ class InterProcessCommunicator(Communicator):
|
||||
|
||||
def stop(self) -> None:
|
||||
self.stop_event.set()
|
||||
self.reader_thread.join()
|
||||
if self.reader_thread is not None:
|
||||
self.reader_thread.join()
|
||||
self.socket.close(linger=0)
|
||||
self.context.destroy(linger=0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user