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

Add configuration option to disable status updates via message bus #331

Merged
merged 3 commits into from
Nov 10, 2023
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
9 changes: 9 additions & 0 deletions src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class DataWritingConfig(BlueapiBaseModel):
group_name: str = "example"


class WorkerEventConfig(BlueapiBaseModel):
"""
Config for event broadcasting via the message bus
"""

broadcast_status_events: bool = True


class EnvironmentConfig(BlueapiBaseModel):
"""
Config for the RunEngine environment
Expand All @@ -60,6 +68,7 @@ class EnvironmentConfig(BlueapiBaseModel):
Source(kind=SourceKind.PLAN_FUNCTIONS, module="dls_bluesky_core.stubs"),
]
data_writing: DataWritingConfig = Field(default_factory=DataWritingConfig)
events: WorkerEventConfig = Field(default_factory=WorkerEventConfig)


class LoggingConfig(BlueapiBaseModel):
Expand Down
5 changes: 4 additions & 1 deletion src/blueapi/service/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def __init__(

self.context.with_config(self.config.env)

self.worker = worker or RunEngineWorker(self.context)
self.worker = worker or RunEngineWorker(
self.context,
broadcast_statuses=self.config.env.events.broadcast_status_events,
)
self.messaging_template = (
messaging_template
or StompMessagingTemplate.autoconfigured(self.config.stomp)
Expand Down
5 changes: 4 additions & 1 deletion src/blueapi/worker/reworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
self,
ctx: BlueskyContext,
start_stop_timeout: float = DEFAULT_START_STOP_TIMEOUT,
broadcast_statuses: bool = True,
) -> None:
self._ctx = ctx
self._start_stop_timeout = start_stop_timeout
Expand All @@ -90,6 +91,7 @@ def __init__(
self._stopping = Event()
self._stopped = Event()
self._stopped.set()
self._broadcast_statuses = broadcast_statuses

def clear_task(self, task_id: str) -> str:
task = self._pending_tasks.pop(task_id)
Expand Down Expand Up @@ -197,7 +199,8 @@ def run(self) -> None:
LOGGER.info("Worker starting")
self._ctx.run_engine.state_hook = self._on_state_change
self._ctx.run_engine.subscribe(self._on_document)
self._ctx.run_engine.waiting_hook = self._waiting_hook
if self._broadcast_statuses:
self._ctx.run_engine.waiting_hook = self._waiting_hook

self._stopped.clear()
self._started.set()
Expand Down