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 amq client to event bus client #466

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
20 changes: 11 additions & 9 deletions src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from requests.exceptions import ConnectionError

from blueapi import __version__
from blueapi.cli.amq import AmqClient
from blueapi.cli.event_bus_client import EventBusClient
from blueapi.config import ApplicationConfig, ConfigLoader
from blueapi.core import DataEvent
from blueapi.messaging import MessageContext
Expand Down Expand Up @@ -135,7 +135,9 @@
"""Listen to events output by blueapi"""
config: ApplicationConfig = obj["config"]
if config.stomp is not None:
amq_client = AmqClient(StompMessagingTemplate.autoconfigured(config.stomp))
event_bus_client = EventBusClient(
StompMessagingTemplate.autoconfigured(config.stomp)
)
else:
raise RuntimeError("Message bus needs to be configured")

Expand All @@ -150,8 +152,8 @@
"Subscribing to all bluesky events from "
f"{config.stomp.host}:{config.stomp.port}"
)
with amq_client:
amq_client.subscribe_to_all_events(on_event)
with event_bus_client:
event_bus_client.subscribe_to_all_events(on_event)
input("Press enter to exit")


Expand Down Expand Up @@ -181,7 +183,7 @@
raise RuntimeError(
"Cannot run plans without Stomp configuration to track progress"
)
amq_client = AmqClient(_message_template)
event_bus_client = EventBusClient(_message_template)
finished_event: deque[WorkerEvent] = deque()

def store_finished_event(event: WorkerEvent) -> None:
Expand All @@ -194,13 +196,13 @@
resp = client.create_task(task)
task_id = resp.task_id

with amq_client:
amq_client.subscribe_to_topics(task_id, on_event=store_finished_event)
with event_bus_client:
event_bus_client.subscribe_to_topics(task_id, on_event=store_finished_event)

Check warning on line 200 in src/blueapi/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/cli/cli.py#L199-L200

Added lines #L199 - L200 were not covered by tests
updated = client.update_worker_task(WorkerTask(task_id=task_id))

amq_client.wait_for_complete(timeout=timeout)
event_bus_client.wait_for_complete(timeout=timeout)

Check warning on line 203 in src/blueapi/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/cli/cli.py#L203

Added line #L203 was not covered by tests

if amq_client.timed_out:
if event_bus_client.timed_out:

Check warning on line 205 in src/blueapi/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/cli/cli.py#L205

Added line #L205 was not covered by tests
logger.error(f"Plan did not complete within {timeout} seconds")
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, message: str) -> None:
_Event = WorkerEvent | ProgressEvent | DataEvent


class AmqClient:
class EventBusClient:
app: MessagingTemplate
complete: threading.Event
timed_out: bool | None
Expand Down
2 changes: 1 addition & 1 deletion src/blueapi/cli/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from blueapi.worker import Task, TrackableTask, WorkerState

from .amq import BlueskyRemoteError
from .event_bus_client import BlueskyRemoteError

T = TypeVar("T")

Expand Down
Loading