Skip to content

Commit

Permalink
return the interface change
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Oct 16, 2024
1 parent 8e7a5af commit a053fd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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 cached_stomp_client() -> StompClient | None:
def messaging_template() -> StompClient | None:
stomp_config: StompConfig | None = config().stomp
if stomp_config is not None:
client = StompClient.for_broker(
Expand Down Expand Up @@ -85,16 +85,16 @@ def setup(config: ApplicationConfig) -> None:

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


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


def _publish_event_streams(
Expand All @@ -106,7 +106,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 := cached_stomp_client()) is not None:
if (template := messaging_template()) 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.cached_stomp_client() is not None
assert interface.messaging_template() is not None

0 comments on commit a053fd3

Please sign in to comment.