Hi! I'm trying to find option similar to `depends_...
# ask-community
s
Hi! I'm trying to find option similar to
depends_on_past
in airflow. We wanted next run of flow to start only when previous run is in Success state. Can anyone help?
a
@Suresh R you can achieve that (any many other state-related patterns) with a state handler: • this one will start a next flow run as soon as the previous flow run ended with Success • this one will skip any next flow run if there is any other flow run in progress of this flow
s
@Anna Geller Thanks,This is helpful!! I have one more query. We have option in prefect to to rerun a failed flow. Do we have option to clear state of succeeded task and rerun it.
a
Yes, on the task run page you can set a state of a task run.
for you it would be: setting it to Failed
s
@Anna Geller I am getting this error when trying to restart the run after setting it to failed state, is this due to my agent lost information of the task.
prefect.exceptions.ClientError: [{'path': ['get_or_create_task_run_info'], 'message': 'Expected type UUID!, found ""; Could not parse UUID:
a
Are you using some env variables when you register your flows? This error happened to one user when he was using env variables during flow registration, but those env variables didn’t exist on the agent during flow runtime. I would definitely cross-check if your registration environment and what you have on your agent matches.
s
ohh Let me check
Some transient error it seems, it is perfectly working fine.Thanks for your help!!!
🙌 1
Do we lose any information if we completely destroy an agent and create an new one, Our flow code is in GitHub.
a
no, you don’t. The flow run history and flow’s metadata is stored in the backend, not on the agent.
s
ok Thanks Again!!!
@Anna Geller One more query, We wanted to schedule some flow everyday between 8AM to 9AM, In case of using state handler, i need to check the time inside the state handler code and trigger the new flow run once 8AM is reached or is there an easy way to do it.
a
wait, do you want to only schedule this flow to run once per day, or do you want it to be running constantly one after the other?
s
I want to schedule it at 8AM (Once per day) and don't want to run it next day if it failed previous day.
I will have to do some work in the background if it fails and then enable it again.
a
ok, then your state handler must be different: it needs to query the flow runs in the descending order, limit to 1 and check if this state is a Success. Then for scheduling, you could use e.g. CronClock:
Copy code
from prefect.schedules import Schedule
from prefect.schedules.clocks import CronClock

schedule = Schedule(clocks=[CronClock("0 8 * * *")])

print(schedule.next(5))
s
Can you point some examples of querying flow runs
a
s
Ok Got it
a
@Suresh R are you on Cloud? I was looking at this state handler and remembered that we have an Automation exactly for that use case 🤦‍♀️ here is how it works: if any flow run from YOUR FLOW NAME changes its state to Failed, then pause its schedule - which has an effect of blocking any future runs if any run ends in a Failed state.
an alternative would be this state handler https://gist.github.com/402592fa014600867461fda217d420ba
s
@Anna Geller Great, We are on cloud, Automation will be easy for us. Thank you!!!
🙌 1