diff --git a/src/prefect/cli/work_queue.py b/src/prefect/cli/work_queue.py index 8e6095d088fb..3b60fc26b8e0 100644 --- a/src/prefect/cli/work_queue.py +++ b/src/prefect/cli/work_queue.py @@ -349,6 +349,7 @@ async def inspect( async with get_client() as client: try: result = await client.read_work_queue(id=queue_id) + app.console.print(Pretty(result)) except ObjectNotFound: if pool: error_message = f"No work queue found: {name!r} in work pool {pool!r}" @@ -356,7 +357,11 @@ async def inspect( error_message = f"No work queue found: {name!r}" exit_with_error(error_message) - app.console.print(Pretty(result)) + try: + status = await client.read_work_queue_status(id=queue_id) + app.console.print(Pretty(status)) + except ObjectNotFound: + pass @work_app.command() diff --git a/src/prefect/client/orchestration.py b/src/prefect/client/orchestration.py index 461f7b2531ff..a91527c72f95 100644 --- a/src/prefect/client/orchestration.py +++ b/src/prefect/client/orchestration.py @@ -92,6 +92,7 @@ Worker, WorkPool, WorkQueue, + WorkQueueStatusDetail, ) from prefect.client.schemas.responses import ( DeploymentResponse, @@ -1036,6 +1037,32 @@ async def read_work_queue( raise return WorkQueue.parse_obj(response.json()) + async def read_work_queue_status( + self, + id: UUID, + ) -> WorkQueueStatusDetail: + """ + Read a work queue status. + + Args: + id: the id of the work queue to load + + Raises: + prefect.exceptions.ObjectNotFound: If request returns 404 + httpx.RequestError: If request fails + + Returns: + WorkQueueStatus: an instantiated WorkQueueStatus object + """ + try: + response = await self._client.get(f"/work_queues/{id}/status") + except httpx.HTTPStatusError as e: + if e.response.status_code == status.HTTP_404_NOT_FOUND: + raise prefect.exceptions.ObjectNotFound(http_exc=e) from e + else: + raise + return WorkQueueStatusDetail.parse_obj(response.json()) + async def match_work_queues( self, prefixes: List[str],