Hello people! How you doing?. I would like to kno...
# ask-community
r
Hello people! How you doing?. I would like to know There is a way with Prefect to prevent a flow execution if that flow was executed early in that day successfully?. please feel free to share github samples as well. Thanks in advance.
k
Hi @Ricardo Portela! Do you want to prevent flows from running again if they already ran?
r
yes. thats right!
Copy code
@task
def prevent_execution():
execution_date(today) = 13/04/2021
max_Date = 12/04/2021
last_execution_date = 12/10/2021


if last_execution_date < max_Date:
   execute flow
else:
   do nothing
something like that
or show log 'this flow already executed'
k
You can read in for previous flow run history from the GraphQL API and then use that to raise a
SKIP
signal in your if statement.
Here is the Client docs. I think
*prefect.client.client.Client.get_flow_run_info*(flow_run_id)
is what you need here.
r
oh let me see, I'll try. thanks for reply
k
Also
prefect.client.client.Client.create_flow_run
j
if you're kicking off that flow from another one, an
idempotency_key
might help (docs). In addition to the API, that can be passed to
StartFlowRun
too.
👍 1
r
I started my script from Crontab.
k
That’s great advice @Jacob Hayes!
r
I just want run this flow based on date(today date), if I already run that flow in that date, I just want to show in log(this flow already run). make sense for you guys?
k
Yes the Client is probably the place to do this
r
ok. thanks! @Kevin Kho @Jacob Hayes