mmrelay 1.2.1__py3-none-any.whl → 1.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mmrelay might be problematic. Click here for more details.

mmrelay/message_queue.py CHANGED
@@ -355,9 +355,9 @@ class MessageQueue:
355
355
 
356
356
  async def _process_queue(self):
357
357
  """
358
- Asynchronously processes messages from the queue, sending each in order while enforcing rate limiting and connection readiness.
358
+ Process queued messages in FIFO order, sending each when the connection is ready and the configured inter-message delay has elapsed.
359
359
 
360
- This method runs as a background task, monitoring the queue, waiting for the connection to be ready, and ensuring a minimum delay between sends. Messages are sent using their provided callable, and optional message mapping is handled after successful sends. The processor logs queue depth warnings, handles errors gracefully, and maintains FIFO order even when waiting for connection or rate limits.
360
+ This background coroutine continuously pulls QueuedMessage items from the internal queue and executes their send_function in the configured executor, enforcing rate limiting (_message_delay) and checking connection/readiness via _should_send_message. After a successful send, it updates last-send timestamps and optionally persists message mapping information via _handle_message_mapping when mapping_info is present and the send result exposes an `id`. The coroutine exits when the queue is stopped or when cancelled; cancellation may drop an in-flight message, which will be logged.
361
361
  """
362
362
  logger.debug("Message queue processor started")
363
363
  current_message = None
@@ -467,18 +467,17 @@ class MessageQueue:
467
467
  self._in_flight = False
468
468
  self._has_current = False
469
469
  break
470
- except Exception as e:
471
- logger.error(f"Error in message queue processor: {e}")
470
+ except Exception:
471
+ logger.exception("Error in message queue processor")
472
472
  await asyncio.sleep(1.0) # Prevent tight error loop
473
473
 
474
474
  def _should_send_message(self) -> bool:
475
475
  """
476
- Return True if it's currently safe to send a message over Meshtastic.
477
-
478
- Checks that the Meshtastic client exists, is connected (supports callable or boolean
479
- `is_connected`), and that a global reconnection flag is not set. Returns False otherwise.
480
- If importing meshtastic utilities raises ImportError, logs a critical error, starts a
481
- background thread to stop this MessageQueue, and returns False.
476
+ Return True if it is currently safe to send a message via Meshtastic.
477
+
478
+ Performs runtime checks: ensures the global reconnecting flag is not set, a Meshtastic client object is available, and — if the client exposes `is_connected` (callable or boolean) — that it reports connected. Returns False if any check fails.
479
+
480
+ If importing the Meshtastic utilities raises ImportError, the method will asynchronously stop this MessageQueue and return False.
482
481
  """
483
482
  # Import here to avoid circular imports
484
483
  try:
@@ -518,18 +517,18 @@ class MessageQueue:
518
517
 
519
518
  def _handle_message_mapping(self, result, mapping_info):
520
519
  """
521
- Store a sent message's mapping (mesh ID → Matrix event) and prune old mappings according to retention settings.
522
-
523
- If `mapping_info` contains the required keys (`matrix_event_id`, `room_id`, `text`), this will call the DB helpers to persist a mapping for `result.id` and then prune older mappings using `mapping_info["msgs_to_keep"]` if present (falls back to DEFAULT_MSGS_TO_KEEP).
524
-
520
+ Persist a sent message mapping (mesh message id → Matrix event) and optionally prune old mappings.
521
+
522
+ If mapping_info contains 'matrix_event_id', 'room_id', and 'text', stores a mapping using result.id as the mesh message id. If 'msgs_to_keep' is present and > 0 it prunes older mappings to retain that many entries; otherwise DEFAULT_MSGS_TO_KEEP is used.
523
+
525
524
  Parameters:
526
- result: The send function's result object; must expose an `id` attribute (the mesh message id).
527
- mapping_info: Dict supplying mapping fields:
528
- - matrix_event_id (str): Matrix event id to associate with the mesh message.
529
- - room_id (str): Matrix room id for the event.
530
- - text (str): The message text to store in the mapping.
531
- - meshnet (optional): Mesh network identifier passed to the store function.
532
- - msgs_to_keep (optional, int): Number of mappings to retain; if > 0, prune older entries.
525
+ result: Send function result object with an `id` attribute (the mesh message id).
526
+ mapping_info (dict): Mapping details. Relevant keys:
527
+ - matrix_event_id (str)
528
+ - room_id (str)
529
+ - text (str)
530
+ - meshnet (optional): passed to the store operation
531
+ - msgs_to_keep (optional, int): number of mappings to retain for pruning
533
532
  """
534
533
  try:
535
534
  # Import here to avoid circular imports
@@ -557,8 +556,8 @@ class MessageQueue:
557
556
  if msgs_to_keep > 0:
558
557
  prune_message_map(msgs_to_keep)
559
558
 
560
- except Exception as e:
561
- logger.error(f"Error handling message mapping: {e}")
559
+ except Exception:
560
+ logger.exception("Error handling message mapping")
562
561
 
563
562
 
564
563
  # Global message queue instance