Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename the messaging_template in the service #673

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def worker() -> TaskWorker:


@lru_cache
def messaging_template() -> StompClient | None:
def stomp_client() -> StompClient | None:
stomp_config = config().stomp
if stomp_config is not None:
template = StompClient.for_broker(
Expand Down Expand Up @@ -83,16 +83,16 @@ def setup(config: ApplicationConfig) -> None:

logging.basicConfig(level=config.logging.level)
worker()
messaging_template()
stomp_client()


def teardown() -> None:
worker().stop()
if (template := messaging_template()) is not None:
if (template := stomp_client()) is not None:
template.disconnect()
context.cache_clear()
worker.cache_clear()
messaging_template.cache_clear()
stomp_client.cache_clear()


def _publish_event_streams(
Expand All @@ -104,7 +104,7 @@ def _publish_event_streams(

def _publish_event_stream(stream: EventStream, destination: DestinationBase) -> None:
def forward_message(event: Any, correlation_id: str | None) -> None:
if (template := messaging_template()) is not None:
if (template := stomp_client()) is not None:
template.send(destination, event, None, correlation_id=correlation_id)

stream.subscribe(forward_message)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/service/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,4 @@ def test_stomp_config(template: StompClient):
"blueapi.service.interface.StompClient.for_broker", return_value=template
):
interface.set_config(ApplicationConfig(stomp=StompConfig()))
assert interface.messaging_template() is not None
assert interface.stomp_client() is not None
Loading