-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(robot-server, api): Wire up protocol engine event bubbling t…
…o robot server (#14766) Closes EXEC-358 Wire up PE event bubbling to the robot server for notifications as an alternative to the current polling that occurs. There are no functional changes. PublisherNotifier is the new interface that handles event management for publishers, using a generic ChangeNotifier that is given to PE as a callback. When PE reports a change in state, the callback fires. PublisherNotifier then iterates through each callback, invoking them. In the future, each publisher that requires access to PE state updates (eg, RunsPublisher) will add relevant callbacks during their initialization via register_publish_callbacks. Each callback will contain the conditional logic required for an MQTT publish to occur.
- Loading branch information
Showing
25 changed files
with
427 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
robot-server/robot_server/service/notifications/change_notifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Simple state change notification interface.""" | ||
import asyncio | ||
|
||
|
||
class ChangeNotifier: | ||
"""An interface to emit or subscribe to state change notifications.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize the ChangeNotifier with an internal Event.""" | ||
self._event = asyncio.Event() | ||
|
||
def notify(self) -> None: | ||
"""Notify all `waiters` of a change.""" | ||
self._event.set() | ||
|
||
async def wait(self) -> None: | ||
"""Wait until the next change notification.""" | ||
self._event.clear() | ||
await self._event.wait() | ||
|
||
def clear(self) -> None: | ||
"""Reset the internal event flag.""" | ||
self._event.clear() |
11 changes: 11 additions & 0 deletions
11
robot-server/robot_server/service/notifications/initialize_notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Utilities for initializing the notification service.""" | ||
from server_utils.fastapi_utils.app_state import AppState | ||
|
||
from .notification_client import initialize_notification_client | ||
from .publisher_notifier import initialize_publisher_notifier | ||
|
||
|
||
async def initialize_notifications(app_state: AppState) -> None: | ||
"""Initialize the notification system for the given app state.""" | ||
initialize_notification_client(app_state) | ||
await initialize_publisher_notifier(app_state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.