How to add edit the CronSchedule with python script (instead of webui)? #4628
-
Currently, i have this code:
This workflow has been registered in prefect server/cloud. I found the web-UI can edit the schedule, but i cannot find any related package in python which allows me to add/remove/edit the CronSchedule or change to another schedule package "IntervalSchedule". So, how can I do it in python? Note that I prefer I can set my schedule out of my flow code with the use of python. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I am not understanding 100% so I'll just try to answer as best I can. First, I just want to make sure you know that you can combine clock1 = clocks.IntervalClock(...)
clock2 = clocks.CronClock(...)
# the full schedule
schedule = Schedule(clocks=[clock1, clock2]) From my understanding, your Flow has a schedule = IntervalSchedule(interval=timedelta(minutes=2))
with Flow("parent-flow", schedule=schedule) as flow:
flow_1
flow.register( project_name = "testing" ) This will replace the schedule for you. Now on the last bit, you want to set the schedule outside of Flow code. You can do something like this from another file: from prefect.utilities.storage import extract_flow_from_file
def register_flow(file, project, labels):
file_path = os.path.abspath(file)
flow = extract_flow_from_file(file_path=file_path)
flow.schedule = IntervalSchedule(interval=timedelta(minutes=2))
flow.register(project_name=project, labels=labels, no_url=True) I don't recommend this though because setting Executor and Results this way will not work. Those need to be defined in the script where you have the Flow. This will work for schedules though. And then as you mentioned, the UI is also another way to edit schedules of registered flows. What is your use case that you need the schedule detached from the Flow code? |
Beta Was this translation helpful? Give feedback.
Hi @mr-tester-william-lo ,
I am not understanding 100% so I'll just try to answer as best I can.
First, I just want to make sure you know that you can combine
CronClocks
andIntervalClocks
to make a more complex schedule. You can do something like:From my understanding, your Flow has a
CronSchedule
and you want to change toIntervalSchedule
. All you need to do is change your weekday_schedule to theIntervalSchedule
and re-register the flow for it to take effect.