Skip to content

Commit

Permalink
Display work queue status details via CLI (#11545)
Browse files Browse the repository at this point in the history
  • Loading branch information
serinamarie authored Jan 4, 2024
1 parent 70dd469 commit 1898227
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/prefect/cli/work_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,19 @@ 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}"
else:
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()
Expand Down
27 changes: 27 additions & 0 deletions src/prefect/client/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
Worker,
WorkPool,
WorkQueue,
WorkQueueStatusDetail,
)
from prefect.client.schemas.responses import (
DeploymentResponse,
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 1898227

Please sign in to comment.