is there any way for a task to know that its flow ...
# ask-community
k
is there any way for a task to know that its flow has been triggered by a Schedule vs. the API? Something in the context perhaps?
👀 1
n
Hi @Kevin Weiler - flow runs scheduled by the Prefect Scheduler will have an
auto_scheduled
flag on the flow run object; when this is true, you know that it was an automatically generated run, otherwise it was created through the API or the UI. Runs created through the API will also have a
created_by
sub object if you’re running in Cloud, which will give you the id of the user that created the run through the UI/API
upvote 1
🙏 1
k
@nicholas - how do I access the flow_run object from inside a task? (let’s say an
@task
decorated function)
n
I think your best bet there is to grab the flow_run_id from context and make a query with the graphql client something like this:
Copy code
query = """ 
query($id: uuid!) {
  flow_run(where: {id: {_eq: $id} }) {
    id
    auto_scheduled
  }
}
"""
client.graphql(query=query, variables=dict(id=context["flow_run_id"]))
@Kevin Kho might have some better advice there though
k
I don’t think you can. What info do you need from the flow object? I think that is the best way to do it if it’s not in the context
k
thanks guys