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
6 changes: 4 additions & 2 deletions src/viam/robot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
GetOperationsResponse,
GetVersionRequest,
GetVersionResponse,
JobStatus,
LogRequest,
ModuleModel,
Operation,
Expand Down Expand Up @@ -890,7 +891,7 @@ async def get_version(self) -> GetVersionResponse:

async def get_machine_status(self) -> GetMachineStatusResponse:
"""
Get status information about the machine's resources and configuration.
Get status information about the machine's resources, configuration, and job statuses.

::

Expand All @@ -899,9 +900,10 @@ async def get_machine_status(self) -> GetMachineStatusResponse:
resource_statuses = machine_status.resources
cloud_metadata = machine_status.resources[0].cloud_metadata
config_status = machine_status.config
job_statuses = machine.get_machine_status().job_statuses

Returns:
viam.proto.robot.GetMachineStatusResponse: current status of the machine (initializing or running), current status of the resources (List[ResourceStatus]) and the revision of the config of the machine.
viam.proto.robot.GetMachineStatusResponse: current status of the machine (initializing or running), current status of the resources (List[ResourceStatus]), the revision of the config of the machine, and current job statuses (List[JobStatus]).

For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
"""
Expand Down
10 changes: 10 additions & 0 deletions src/viam/robot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from viam.errors import ViamGRPCError
from viam.proto.common import ResourceName
from viam.proto.robot import (
JobStatus,
ResourceNamesRequest,
ResourceNamesResponse,
StopAllRequest,
Expand Down Expand Up @@ -67,3 +68,12 @@ async def StopAll(self, stream: Stream[StopAllRequest, StopAllResponse]) -> None
if errors:
raise ViamGRPCError(f'Failed to stop components named {", ".join(errors)}')
await stream.send_message(StopAllResponse())

async def GetMachineStatus(self, stream: Stream[ResourceNamesRequest, ResourceNamesResponse]) -> None:
request = await stream.recv_message()
assert request is not None
# Placeholder for retrieving actual job statuses.
# This would typically involve retrieving actual job statuses from the robot's internal state or a job management system.
job_statuses = []
response = ResourceNamesResponse(resources=self._generate_metadata(), job_statuses=job_statuses)
await stream.send_message(response)
6 changes: 5 additions & 1 deletion tests/test_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
GetOperationsResponse,
GetVersionRequest,
GetVersionResponse,
JobStatus,
Operation,
ResourceNamesRequest,
ResourceNamesResponse,
Expand Down Expand Up @@ -109,7 +110,8 @@
name=ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="arm", name="arm1"),
state=ResourceStatus.State.STATE_READY,
)
]
],
job_statuses=[JobStatus(job_name="my_job", recent_successful_runs=[], recent_failed_runs=[])]
)


Expand Down Expand Up @@ -367,6 +369,8 @@ async def test_get_machine_status(self, service: RobotService):
async with await RobotClient.with_channel(channel, RobotClient.Options()) as client:
statuses = await client.get_machine_status()
assert statuses == GET_MACHINE_STATUS_RESPONSE
assert len(statuses.job_statuses) == 1
assert statuses.job_statuses[0].job_name == "my_job"

async def test_get_operations(self, service: RobotService):
async with ChannelFor([service]) as channel:
Expand Down
Loading