Skip to content

Commit

Permalink
Rename handler "state" to "worker_state" (#521)
Browse files Browse the repository at this point in the history
It is the worker state rather than the overall state of blueapi.

The "state" name may be used to replace the current "initialized" in
order to provide more context about the "environment".

Prerequisite to #514.
  • Loading branch information
joeshannon authored Jun 25, 2024
1 parent 6a9efe1 commit 1cc2b8a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/blueapi/service/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def active_task(self) -> TrackableTask | None:
return self._worker.get_active_task()

@property
def state(self) -> WorkerState:
def worker_state(self) -> WorkerState:
return self._worker.state

def pause_worker(self, defer: bool | None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/blueapi/service/handler_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def active_task(self) -> TrackableTask | None:

@property
@abstractmethod
def state(self) -> WorkerState:
def worker_state(self) -> WorkerState:
"""State of the worker"""

@abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def get_active_task(handler: BlueskyHandler = Depends(get_handler)) -> WorkerTas
@app.get("/worker/state")
def get_state(handler: BlueskyHandler = Depends(get_handler)) -> WorkerState:
"""Get the State of the Worker"""
return handler.state
return handler.worker_state


# Map of current_state: allowed new_states
Expand Down Expand Up @@ -304,7 +304,7 @@ def set_state(
- If reason is set, the reason will be passed as the reason for the Run failure.
- **All other transitions return 400: Bad Request**
"""
current_state = handler.state
current_state = handler.worker_state
new_state = state_change_request.new_state
if (
current_state in _ALLOWED_TRANSITIONS
Expand All @@ -325,7 +325,7 @@ def set_state(
else:
response.status_code = status.HTTP_400_BAD_REQUEST

return handler.state
return handler.worker_state


def start(config: ApplicationConfig):
Expand Down
8 changes: 4 additions & 4 deletions src/blueapi/service/subprocess_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def active_task(self) -> TrackableTask | None:
return self._run_in_subprocess(active_task)

@property
def state(self) -> WorkerState:
return self._run_in_subprocess(state)
def worker_state(self) -> WorkerState:
return self._run_in_subprocess(worker_state)

def pause_worker(self, defer: bool | None) -> None:
return self._run_in_subprocess(pause_worker, [defer])
Expand Down Expand Up @@ -156,8 +156,8 @@ def active_task() -> TrackableTask | None:
return get_handler().active_task


def state() -> WorkerState:
return get_handler().state
def worker_state() -> WorkerState:
return get_handler().worker_state


def pause_worker(defer: bool | None) -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/service/test_subprocess_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_reload():
def test_raises_if_not_started():
sp_handler = SubprocessHandler()
with pytest.raises(HandlerNotStartedError):
assert sp_handler.state is None
assert sp_handler.worker_state is None


class DummyHandler(BlueskyHandler):
Expand Down Expand Up @@ -105,7 +105,7 @@ def active_task(self) -> TrackableTask | None:
return None

@property
def state(self) -> WorkerState:
def worker_state(self) -> WorkerState:
return WorkerState.IDLE

def pause_worker(self, defer: bool | None) -> None: ...
Expand Down Expand Up @@ -171,7 +171,7 @@ def run_in_same_process(func, args=None):

assert sp_handler.active_task == dummy_handler.active_task

assert sp_handler.state == dummy_handler.state
assert sp_handler.worker_state == dummy_handler.worker_state

sp_handler.pause_worker(True)

Expand Down

0 comments on commit 1cc2b8a

Please sign in to comment.