Thread
#prefect-community
    Kyle McChesney

    Kyle McChesney

    1 year ago
    I am writing a small Lambda function to trigger a prefect flow run on demand. I was wondering if anyone has done similar and could let me know if these queries look right • given a flow name, get the latest version’s id
    LATEST_FLOW_BY_NAME = gql(
        '''
            query LatestFlowByName($name: String) {
              flow(
                where: {name: {_eq: $name}},
                order_by: {version: desc},
                limit: 1,
              )
              {
                id
              }
            }
        ''',
    )
    with:
    variable_values={'name': name}
    • trigger a flow run
    CREATE_FLOW_RUN = gql(
        '''
            mutation CreateFlowRun($input: create_flow_run_input!) {
                create_flow_run(input: $input) {id}
            }
        ''',
    )
    with:
    variable_values={
        'input': {
            'flow_id': flow_id,
            'parameters': parameters,
        },
    },
    My goal here is to specify as little as possible, to ensure the flow runs with the defaults configured for it. I.E. I don’t want to muck with the RunConfig, etc. I am mostly concerned about my logic for getting the latest flow run. I tried to grok the flow groups / versions tables but did not have much luck.
    Kevin Kho

    Kevin Kho

    1 year ago
    Hey @Kyle McChesney, I think the concern here is that the
    LatestFlowByName
    is not guaranteed to pull the right now unless you immediately registered? You may also have different projects that contain a flow with the same name. The other queries look good to be.
    Kyle McChesney

    Kyle McChesney

    1 year ago
    Not sure I follow the first part. The flows are registered else where, as part of a CI process (when a PR is merged)
    Kevin Kho

    Kevin Kho

    1 year ago
    If you have two projects “A” and “B” that both contain a flow named “myflow”. How is it guaranteed you would get the “myflow” of project A?
    Kyle McChesney

    Kyle McChesney

    1 year ago
    oh I see, I misunderstood. Its all related to the flow name overlap issue. Assuming flow names are unique, this latest query should work?
    Kevin Kho

    Kevin Kho

    1 year ago
    I believe so. I haven’t used that route specifically but I expect it to yep
    Kyle McChesney

    Kyle McChesney

    1 year ago
    much appreciated @Kevin Kho!