Updated tests and added core live value handling
Removed useless tests, will need to complete a more comprehensive test suite however this is not the priority right now Added a live value dict in the core whose values are populated by the core's input thread
This commit is contained in:
@@ -6,7 +6,7 @@ import logging
|
||||
from queue import Empty, Full, Queue
|
||||
import threading
|
||||
from threading import RLock, Thread
|
||||
from time import monotonic, sleep
|
||||
from time import monotonic, monotonic_ns, sleep
|
||||
from uuid import UUID
|
||||
|
||||
from dynalab_core.constants import HELLO_PACKET
|
||||
@@ -15,7 +15,7 @@ from dynalab_core.protocols.errors import (
|
||||
ConnectorRegistryAlreadyRegisteredError,
|
||||
)
|
||||
from dynalab_core.protocols.packets import ProtocolMessage
|
||||
from dynalab_core.protocols.packets.data import ValueDescriptor
|
||||
from dynalab_core.protocols.packets.data import ValueBatch, ValueDescriptor
|
||||
from dynalab_core.protocols.packets.handshake import (
|
||||
ConnectorHello,
|
||||
HandshakeAccepted,
|
||||
@@ -208,20 +208,34 @@ class ConnectorEndpoint:
|
||||
"thread_name": self._input_worker_thread.name,
|
||||
},
|
||||
)
|
||||
last_log = 0
|
||||
while not self._stop_event.is_set():
|
||||
now = monotonic_ns()
|
||||
messages: list[ProtocolMessage] = []
|
||||
try:
|
||||
message = self._get_ingress_packet_no_wait()
|
||||
while not self._packet_ingress_queue.empty():
|
||||
messages.append(self._get_ingress_packet_no_wait())
|
||||
except Empty:
|
||||
self._stop_event.wait(0.01)
|
||||
continue
|
||||
else:
|
||||
if isinstance(message, Heartbeat):
|
||||
self._heartbeat_ingress_queue.put_nowait(message)
|
||||
elif isinstance(message, ValueDescriptor):
|
||||
if message.signal_id in (
|
||||
signal.id for signal in self._connector_hello.signals
|
||||
):
|
||||
self._core_input_queue.put_nowait(message)
|
||||
for message in messages:
|
||||
if isinstance(message, Heartbeat):
|
||||
self._heartbeat_ingress_queue.put_nowait(message)
|
||||
elif isinstance(message, ValueDescriptor):
|
||||
if message.signal_id in (
|
||||
signal.id for signal in self._connector_hello.signals
|
||||
):
|
||||
self._core_input_queue.put_nowait(message)
|
||||
elif isinstance(message, ValueBatch):
|
||||
for value in message.values:
|
||||
if value.signal_id in (
|
||||
signal.id for signal in self._connector_hello.signals
|
||||
):
|
||||
self._core_input_queue.put_nowait(value)
|
||||
|
||||
if now > last_log + 2000 * 1_000_000:
|
||||
log.debug(f"Endpoint queue size: {self._packet_ingress_queue.qsize()}")
|
||||
last_log = now
|
||||
self._input_worker_stopped_event.set()
|
||||
log.debug(
|
||||
"Connector endpoint input worker %s stopped",
|
||||
|
||||
Reference in New Issue
Block a user