Hi, I want to change the schedule of a Flow in my ...
# prefect-community
n
Hi, I want to change the schedule of a Flow in my code. As an example I set
flow.schedule = Schedule(clocks=[CronClock("* * * * *")])
which works fine and later want to add another schedule or delete the current one. My idea is to use GraphQL with the
set_flow_group_schedule
and
delete_flow_group_schedule
methods.
k
Hey @Nico Neumann , could you move the graphql result to the thread when you get the chance so we don’t crowd the main channel? I think there is a distinction here between flow group schedule and flow schedule like you have hinted. The flow group schedule is the one defined in the UI and that does not go away as your re-register. The one defined by code is the flow schedule and goes away with re-registration. So we need to figure out how to delete the flow schedule instead of flow group
n
Now I first tried to query my schedule to see if it is registered correctly in Prefect Cloud
Copy code
query {
    flow {
      id
      name
      flow_group_id
      schedule
    }
}
And I can see it:
Copy code
...
"flow_group_id": "{flow_group_id}",
"schedule": {
    "clocks": [
      {
        "cron": "* * * * *",
        "type": "CronClock",
        "day_or": true,
        "labels": null,
        "end_date": null,
        "start_date": null,
        "__version__": "1.1.0",
        "parameter_defaults": {}
      }
    ],
    "filters": [],
    "or_filters": [],
    "__version__": "1.1.0",
    "adjustments": [],
    "not_filters": []
  }
},
...
Now I want to delete the schedule using the
flow_group_id
and I get
success=true
back:
Copy code
mutation {
    delete_flow_group_schedule(input: {
      flow_group_id: "{flow_group_id}") {
        success
    }
}
But when I run the query again, my schedule is still there and running. I also checked it in the Prefect Cloud UI. It says I cannot delete it trough the UI because it was created through code. When I add a schedule through UI now for testing, I can delete it with the
delete_flow_group_schedule
command above. But I cannot delete the schedule created through the code.
k
Thank you for moving it!
n
@Kevin Kho thank you for your reply! I just saw in the query that both schedules are at different places in the query: The one created through code is at
flow.schedule
and the one created through the UI at
flow.flow_group.schedule
k
Exactly yeah
I think you need to do something like pulling the serialized version of the Flow, updating it, and then re-registering it. I don’t think there is an easy way to edit
flow.schedule
. Would using the
flow_group
schedule work for your use case? Could you tell me more?
n
My idea is to have a flow running at a specific time and later on I might want to change the schedule or delete it. I was not aware of the difference between the schedules. So instead I could just register the flow without a schedule and then use
set_flow_group_schedule
to set it? In this way I should then be able to delete it later with
delete_flow_group_schedule
?
k
I guess that’s easier yep because modifying the Flow object with a schedule attached requires some form of re-registration I think
n
Thank you very much! Really great support here of everyone 😊
k
Thank you!