Skip to content
Draft
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
15 changes: 15 additions & 0 deletions src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from typing import Any

from bluesky.callbacks.tiled_writer import TiledWriter
from bluesky.protocols import Readable, Reading
from bluesky.run_engine import call_in_bluesky_event_loop
from bluesky.utils import maybe_await
from bluesky_stomp.messaging import StompClient
from bluesky_stomp.models import Broker, DestinationBase, MessageTopic
from fastapi import status
Expand Down Expand Up @@ -342,6 +345,18 @@ def get_python_env(
return get_python_environment(config=scratch, name=name, source=source)


def read_device(addr: str) -> dict[str, Reading[Any]]:
device = context().find_device(addr)

if not isinstance(device, Readable):
raise TypeError("Requested device is not readable")

return call_in_bluesky_event_loop(
maybe_await(device.read()),
timeout=10.0,
)


@dataclass
class SubHandles:
worker: int
Expand Down
9 changes: 9 additions & 0 deletions src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,15 @@ def get_python_environment(
return runner.run(interface.get_python_env, name, source)


@secure_router_v1.get("/device-read/{device}", tags=[Tag.DEVICE])
@start_as_current_span(TRACER)
def read_device(
runner: Annotated[WorkerDispatcher, Depends(_runner)],
device: str,
):
return runner.run(interface.read_device, device)


@open_router.get("/healthz", status_code=status.HTTP_200_OK, tags=[Tag.META])
def health_probe() -> HealthProbeResponse:
"""If able to serve this, server is live and ready for requests."""
Expand Down
Loading