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
4 changes: 2 additions & 2 deletions helm/blueapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ A Helm chart deploying a worker pod that runs Bluesky plans
| tracing | object | `{"fastapi":{"excludedURLs":"/healthz"},"otlp":{"enabled":false,"protocol":"http/protobuf","server":{"host":"http://opentelemetry-collector.tracing","port":4318}}}` | Exclude health probe requests from tracing by default to prevent spamming |
| volumeMounts | list | `[]` | Additional volumeMounts on the output StatefulSet definition. Define how volumes are mounted to the container referenced by using the same name. |
| volumes | list | `[]` | Additional volumes on the output StatefulSet definition. Define volumes from e.g. Secrets, ConfigMaps or the Filesystem |
| worker | object | `{"api":{"url":"http://0.0.0.0:8000/"},"env":{"sources":[{"kind":"planFunctions","module":"dodal.plans"},{"kind":"planFunctions","module":"dodal.plan_stubs.wrapped"}]},"logging":{"graylog":{"enabled":false,"url":"tcp://graylog-log-target.diamond.ac.uk:12231/"},"level":"INFO"},"scratch":{"repositories":[],"root":"/workspace"},"stomp":{"auth":{"password":"guest","username":"guest"},"enabled":false,"url":"tcp://rabbitmq:61613/"}}` | Config for the worker goes here, will be mounted into a config file |
| worker | object | `{"api":{"url":"http://0.0.0.0:8000/"},"env":{"sources":[{"kind":"planFunctions","module":"dodal.plans"}]},"logging":{"graylog":{"enabled":false,"url":"tcp://graylog-log-target.diamond.ac.uk:12231/"},"level":"INFO"},"scratch":{"repositories":[],"root":"/workspace"},"stomp":{"auth":{"password":"guest","username":"guest"},"enabled":false,"url":"tcp://rabbitmq:61613/"}}` | Config for the worker goes here, will be mounted into a config file |
| worker.api.url | string | `"http://0.0.0.0:8000/"` | 0.0.0.0 required to allow non-loopback traffic If using hostNetwork, the port must be free on the host |
| worker.env.sources | list | `[{"kind":"planFunctions","module":"dodal.plans"},{"kind":"planFunctions","module":"dodal.plan_stubs.wrapped"}]` | modules (must be installed in the venv) to fetch devices/plans from |
| worker.env.sources | list | `[{"kind":"planFunctions","module":"dodal.plans"}]` | modules (must be installed in the venv) to fetch devices/plans from |
| worker.logging | object | `{"graylog":{"enabled":false,"url":"tcp://graylog-log-target.diamond.ac.uk:12231/"},"level":"INFO"}` | Configures logging. Port 12231 is the `dodal` input on graylog which will be renamed `blueapi` |
| worker.scratch | object | `{"repositories":[],"root":"/workspace"}` | If initContainer is enabled the default branch of python projects in this section are installed into the venv *without their dependencies* |
| worker.stomp | object | `{"auth":{"password":"guest","username":"guest"},"enabled":false,"url":"tcp://rabbitmq:61613/"}` | Message bus configuration for returning status to GDA/forwarding documents downstream Password may be in the form ${ENV_VAR} to be fetched from an environment variable e.g. mounted from a SealedSecret |
2 changes: 0 additions & 2 deletions helm/blueapi/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ worker:
# module: dodal.beamlines.adsim
- kind: planFunctions
module: dodal.plans
- kind: planFunctions
module: dodal.plan_stubs.wrapped
# -- Message bus configuration for returning status to GDA/forwarding documents downstream
# Password may be in the form ${ENV_VAR} to be fetched from an environment variable e.g. mounted from a SealedSecret
stomp:
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
description = "Lightweight bluesky-as-a-service wrapper application. Also usable as a library."
dependencies = [
"tiled[client]>=0.2.4",
"bluesky[plotting]>=1.14.0", # plotting includes matplotlib, required for BestEffortCallback in run plans
"bluesky[plotting] @ git+https://github.com/bluesky/bluesky.git@main", # plotting includes matplotlib, required for BestEffortCallback in run plans

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot do git dependencies and have a published release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah yeah. Just doing this for now until there's a new release of bluesky that has the new typing changes

"ophyd-async>=0.13.5",
"aioca",
"pydantic>=2.0",
Expand All @@ -26,8 +26,8 @@ dependencies = [
"fastapi>=0.112.0",
"uvicorn>=0.52.1",
"requests",
"GitPython>=3.1.58", #security base min https://github.com/advisories/GHSA-4gmw-gg2m-w46p
"event-model==1.24.0", # https://github.com/DiamondLightSource/blueapi/issues/684
"GitPython>=3.1.58", #security base min https://github.com/advisories/GHSA-4gmw-gg2m-w46p
"event-model==1.24.0", # https://github.com/DiamondLightSource/blueapi/issues/684
"bluesky-stomp>=0.1.6",
"opentelemetry-distro>=0.48b0",
"opentelemetry-instrumentation-fastapi>=0.48b0",
Expand All @@ -37,6 +37,7 @@ dependencies = [
"graypy>=2.1.0",
"httpx>=0.28.1",
"aiohttp>=3.13.5",
"bluesky-tiled-plugins>=2.0.11",
]
dynamic = ["version"]
license.file = "LICENSE"
Expand Down
20 changes: 17 additions & 3 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from types import ModuleType, NoneType, UnionType
from typing import Any, TypeVar, Union, get_args, get_origin, get_type_hints

import bluesky.plan_stubs as bps
from bluesky.protocols import HasName
from bluesky.run_engine import RunEngine
from bluesky.run_engine import RunEngine, RunEngineMetadata
from ophyd_async.core import NotConnectedError, PathProvider
from pydantic import (
BaseModel,
Expand Down Expand Up @@ -52,6 +53,16 @@

LOGGER = logging.getLogger(__name__)

DEFAULT_PLAN_STUBS = [
bps.abs_set,
bps.rel_set,
bps.mv,
bps.mvr,
bps.sleep,
bps.wait,
bps.rd,
bps.stop,
]

if "ophyd" in sys.modules:
# This is an awful hack/workaround to avoid blueapi hanging on shutdown when
Expand Down Expand Up @@ -137,6 +148,9 @@ def __post_init__(self, configuration: ApplicationConfig | None):
if not configuration:
return

for plan_stub in DEFAULT_PLAN_STUBS:
self.register_plan(plan_stub)

if (nt_conf := configuration.numtracker) is not None:
if configuration.env.metadata is not None:
self.numtracker = NumtrackerClient(url=nt_conf.url)
Expand All @@ -155,7 +169,7 @@ def __post_init__(self, configuration: ApplicationConfig | None):
# local reference so it's available in _update_scan_num
numtracker = self.numtracker

async def _update_scan_num(md: dict[str, Any]) -> int:
async def _update_scan_num(md: RunEngineMetadata) -> int:
scan = await numtracker.create_scan(
md["instrument_session"], md["instrument"]
)
Expand Down Expand Up @@ -203,7 +217,7 @@ def find_device(self, addr: str | list[str]) -> Device | None:

def with_config(self, config: EnvironmentConfig) -> None:
if config.metadata is not None:
self.run_engine.md |= config.metadata.model_dump()
self.run_engine.md.update(config.metadata.model_dump())

package_map = metadata.packages_distributions()
packages = {src.module.split(".")[0] for src in config.sources}
Expand Down
2 changes: 1 addition & 1 deletion src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from multiprocessing.connection import Connection
from typing import Any

from bluesky.callbacks.tiled_writer import TiledWriter
from bluesky_stomp.messaging import StompClient
from bluesky_stomp.models import Broker, DestinationBase, MessageTopic
from bluesky_tiled_plugins import TiledWriter
from tiled.client import from_uri

from blueapi.cli.scratch import get_python_environment
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class ConcreteStoppable(Stoppable):
def name(self) -> str:
return "Concrete"

def stop(self, success: bool = True):
def stop(self, *, success: bool = True):
pass


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 @@ -142,7 +142,7 @@ def test_get_plan(context_mock: MagicMock):
class MyDevice(Stoppable):
name: str

def stop(self, success: bool = True) -> None:
def stop(self, *, success: bool = True) -> None:
pass


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/service/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def client_with_cors(
class MinimalDevice(Stoppable):
name: str

def stop(self, success: bool = True):
def stop(self, *, success: bool = True):
pass


Expand Down
Loading
Loading