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

Almost working tiled insertion #781

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ classifiers = [
]
description = "Lightweight bluesky-as-a-service wrapper application. Also usable as a library."
dependencies = [
"tiled",
"json_merge_patch",
"jsonpatch",
"pyarrow",
"bluesky>=1.13",
"ophyd",
"nslsii",
Expand Down Expand Up @@ -95,7 +99,8 @@ addopts = """
--ignore=src/blueapi/startup
"""
# https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings
filterwarnings = ["error", "ignore::DeprecationWarning"]
# Unignore UserWarning after Pydantic warning removed from bluesky/bluesky and release
filterwarnings = ["error", "ignore::DeprecationWarning", "ignore::UserWarning"]
# Doctest python code in docs, python code in src docstrings, test functions in tests
testpaths = "docs src tests"
asyncio_mode = "auto"
Expand Down
14 changes: 13 additions & 1 deletion src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class StompConfig(BaseModel):
auth: BasicAuthentication | None = None


class TiledConfig(BaseModel):
"""
Config for connecting to a tiled instance
"""

host: str
port: int


class WorkerEventConfig(BlueapiBaseModel):
"""
Config for event broadcasting via the message bus
Expand Down Expand Up @@ -111,7 +120,9 @@ class OIDCConfig(BlueapiBaseModel):
description="URL to fetch OIDC config from the provider"
)
client_id: str = Field(description="Client ID")
client_audience: str = Field(description="Client Audience(s)", default="blueapi")
client_audience: str | list[str] | None = Field(
description="Client Audience(s)", default="blueapi"
)

@cached_property
def _config_from_oidc_url(self) -> dict[str, Any]:
Expand Down Expand Up @@ -160,6 +171,7 @@ class ApplicationConfig(BlueapiBaseModel):
"""

stomp: StompConfig | None = None
tiled: TiledConfig | None = None
env: EnvironmentConfig = Field(default_factory=EnvironmentConfig)
logging: LoggingConfig = Field(default_factory=LoggingConfig)
api: RestConfig = Field(default_factory=RestConfig)
Expand Down
4 changes: 3 additions & 1 deletion src/blueapi/service/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def decode_jwt(self, json_web_token: str):
signing_key.key,
algorithms=self._server_config.id_token_signing_alg_values_supported,
verify=True,
audience=self._server_config.client_audience,
# audience=self._server_config.client_audience,
issuer=self._server_config.issuer,
)

Expand Down Expand Up @@ -169,6 +169,7 @@ def poll_for_token(
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
"device_code": device_code,
"client_id": self._server_config.client_id,
"client_secret": "secret",
},
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
Expand All @@ -184,6 +185,7 @@ def start_device_flow(self):
self._server_config.device_authorization_endpoint,
data={
"client_id": self._server_config.client_id,
"client_secret": "secret",
"scope": SCOPES,
},
headers={"Content-Type": "application/x-www-form-urlencoded"},
Expand Down
9 changes: 6 additions & 3 deletions src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from blueapi.worker.event import TaskStatusEnum, WorkerState
from blueapi.worker.task import Task
from blueapi.worker.task_worker import TaskWorker, TrackableTask
from blueapi.worker.tiled import TiledConnection

"""This module provides interface between web application and underlying Bluesky
context and worker"""
Expand Down Expand Up @@ -40,9 +41,11 @@ def context() -> BlueskyContext:

@cache
def worker() -> TaskWorker:
conf = config()
worker = TaskWorker(
context(),
broadcast_statuses=config().env.events.broadcast_status_events,
broadcast_statuses=conf.env.events.broadcast_status_events,
tiled_inserter=TiledConnection(conf.tiled) if conf.tiled else None,
)
worker.start()
return worker
Expand Down Expand Up @@ -144,10 +147,10 @@ def clear_task(task_id: str) -> str:
return worker().clear_task(task_id)


def begin_task(task: WorkerTask) -> WorkerTask:
def begin_task(task: WorkerTask, token: str | None) -> WorkerTask:
"""Trigger a task. Will fail if the worker is busy"""
if task.task_id is not None:
worker().begin_task(task.task_id)
worker().begin_task(task.task_id, token=token)
return task


Expand Down
Loading
Loading