<@ULVA73B9P> is there a way to catch and alert whe...
# ask-marvin
m
@Marvin is there a way to catch and alert when a deployment change state from Active to Not Ready?
m
thought for 437.7 seconds
Short answer: not directly on that specific transition, but you can alert on it with Automations by watching the underlying cause (worker/work-queue health), or by emitting a small custom event when a deployment becomes Not Ready. A couple clarifying questions to make sure I point you to the best option: - Are you on Prefect 3.x Cloud or an open-source server? - When you say “Active,” do you mean the deployment’s schedule toggle is active, or the deployment is showing “Ready” in the UI? In 3.x, “Ready/Not Ready” is driven by worker/queue polling, while the schedule “Active/Inactive” is separate. What “Not Ready” means in 3.x - A deployment is Ready when its work queue has been polled by a worker recently; it’s Not Ready when no poll has occurred within the readiness window (or the queue is paused). - More on work pools/queues: Work pools/queues in Prefect 3.x Ways to catch and alert Option A — Alert on worker/work-queue health (recommended) - Since Not Ready is caused by a queue not being polled, set an Automation to notify you when a specific work queue hasn’t been polled for N seconds or is unhealthy. This catches the condition that will make deployments Not Ready. - In Cloud: create an Automation with a proactive trigger tied to your work queue or work pool health, then add a Send Notification action (Slack/Teams/email via a notification block). - Docs: - Creating automations - Event triggers - Worker health checks overview - Work queue status endpoint (what “healthy”/last polled means): /work-queues/{id}/status Notes: - The Prefect CLI does not currently have “automation create”; it supports listing/inspecting/enabling/disabling (verified with
prefect automation --help
). - Use the UI for setup, or the REST API if you need to create them programmatically. Option B — Emit a custom event when a deployment becomes Not Ready, then automate If you’d like a deployment-specific alert, run a tiny monitoring flow on an interval that checks the deployment’s status and emits an event when it’s NOT_READY. Then create an Automation with an Event Trigger that matches your custom event and sends a notification. Example flow (minimal) that checks a deployment and emits an event:
Copy code
import os
import httpx
from prefect import flow
from prefect.events.utilities import emit_event

API_URL = os.environ["PREFECT_API_URL"]
API_KEY = os.environ["PREFECT_API_KEY"]

def get_deployment_status(deployment_id: str) -> str:
    r = httpx.get(
        f"{API_URL}/deployments/{deployment_id}",
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=10.0,
    )
    r.raise_for_status()
    return r.json()["status"]  # "READY" or "NOT_READY"

@flow
def check_deployment_readiness(deployment_id: str, deployment_name: str):
    status = get_deployment_status(deployment_id)
    if status != "READY":
        emit_event(
            event="deployment.readiness.not_ready",
            resource={
                "prefect.resource.id": f"prefect.deployment.{deployment_id}",
                "prefect.name": deployment_name,
            },
            payload={"status": status},
        )
Then: - Create an Automation with an Event Trigger - expect:
deployment.readiness.not_ready
- match resource:
prefect.deployment.<your-id>
- action: Send Notification (Slack/Teams/email via a configured notification block) - Reference: Creating automations, Event triggers, and the event utility used above: Events concept
FYI on built-in events - Prefect emits many flow run and system events, but there isn’t a documented, first-class “Deployment Ready → Not Ready” event you can pick from a list today. That’s why the two approaches above are the most reliable. If you can share: - whether you’re on Cloud or OSS, - the notification channel you want (Slack/Teams/email), - and whether you want to monitor specific deployments or any deployment in a pool, …I can give you exact UI steps (and/or a ready-to-deploy monitor) tailored to your setup.
m
@Marvin I am working of prefect 3.x cloud, I mean Ready/Not Ready
m
Error:
Sorry, I encountered an error while processing your request. Please try again.