<@ULVA73B9P> Does prefect emit an event when a sch...
# ask-marvin
f
@Marvin Does prefect emit an event when a schedule is disabled or re-enabled ? I’m trying to inform my team that a flow has been disabled, programmatically
m
It appears that Prefect currently does not emit specific events when a schedule is disabled or re-enabled. However, you can use Prefect's automations and custom event hooks to achieve similar functionality. ### Solution Using Automations (2.x) For Prefect 2.x users: 1. Utilize Prefect Automations to monitor your deployment and trigger notifications when specific properties change. Automations can trigger on state changes, which might cover enabling or disabling schedules indirectly. 2. You can set up an automation that triggers when the state of deployment changes, which might cover cases when schedules are updated. Example: You can create an automation to monitor logs or states and trigger notifications to your team. ### Custom Notifications in Prefect 3.x For Prefect 3.x users: 1. Prefect 3.x does not directly emit events for schedule changes. However, you can manually handle these events by updating the deployment script to notify your team whenever you change the
active
state of a schedule. Example:
Copy code
python
from prefect.deployments import Deployment
from prefect.orion.schemas.schedules import CronSchedule

# Define your deployment with the schedule
deployment = Deployment(
    name="example_deployment",
    flow_name="example_flow",
    schedule=CronSchedule(cron="0 0 * * *", timezone="UTC", active=False),
)

def notify_team(schedule_status):
    # Your custom notification logic here, e.g., send an email or Slack message
    print(f"Schedule has been {schedule_status}")

# Toggle the schedule's active status and notify the team
schedule_active = False

if schedule_active:
    deployment.schedule.active = True
    notify_team("re-enabled")
else:
    deployment.schedule.active = False
    notify_team("disabled")

# Apply the deployment update
deployment.apply()
This script manually updates the schedule and includes a function to notify your team of the change. ### Resources - Prefect Automations: https://docs-2.prefect.io/latest/concepts/automations/ - Prefect 3.x Schedules: https://docs-3.prefect.io/3.0/automate/add-schedules Using these approaches, you can programmatically inform your team when a flow's schedule is disabled or re-enabled. If there's any other specific requirement or challenge you face, feel free to ask!
f
tx !