k

    Kevin Weiler

    11 months ago
    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?
    nicholas

    nicholas

    11 months ago
    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
    k

    Kevin Weiler

    11 months ago
    @nicholas - how do I access the flow_run object from inside a task? (let’s say an
    @task
    decorated function)
    nicholas

    nicholas

    11 months ago
    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:
    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
    Kevin Kho

    Kevin Kho

    11 months ago
    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

    Kevin Weiler

    11 months ago
    thanks guys