<@ULVA73B9P> can i find named workers for a certai...
# ask-marvin
p
@Marvin can i find named workers for a certain work pool/queue via the CLI and API?
m
thought for 460.7 seconds
Short answer: - CLI: No — there isn’t a command to list workers. - API: Yes — you can list workers for a work pool; there isn’t a queue-level listing. Details CLI - There’s no
prefect worker ls/inspect
(the worker CLI only has
start
). -
prefect work-pool inspect
and
prefect work-queue
commands do not list workers. API (Python client) - You can query workers for a specific work pool via the Prefect client. Example:
Copy code
from prefect.client.orchestration import get_client
from prefect.client.schemas.filters import WorkerFilter, WorkerFilterStatus

async def list_workers(pool_name: str):
    async with get_client() as client:
        workers = await client._work_pool_client.read_workers_for_work_pool(
            work_pool_name=pool_name,
            worker_filter=WorkerFilter(
                status=WorkerFilterStatus(any_=["ONLINE", "OFFLINE"])
            ),
            offset=0,
            limit=200,
        )
        for w in workers:
            print(w.name, w.status, w.last_heartbeat_time)
Notes: - Fields available include:
name
,
status
(ONLINE/OFFLINE),
last_heartbeat_time
,
heartbeat_interval_seconds
, plus standard ids/timestamps. - The server does not track which specific work queues a worker is polling, so you can’t filter workers by queue. API (REST) - List/filter workers for a pool: - POST
/work_pools/{work_pool_name}/workers/filter
- Example:
Copy code
curl -X POST "$PREFECT_API_URL/api/work_pools/my-pool/workers/filter" \
  -H "Authorization: Bearer $PREFECT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "workers": {
          "status": { "any_": ["ONLINE"] }
        },
        "offset": 0,
        "limit": 100
      }'
- Delete a worker: - DELETE
/work_pools/{work_pool_name}/workers/{name}
If you’re specifically trying to find “workers for a queue,” that’s not exposed because the server doesn’t persist which queues a given worker is polling. If you can share what you want to do with queue-level visibility, I can suggest a practical workaround.