https://prefect.io logo
r

Rohit

06/27/2022, 11:38 AM
Hello community! I started with Prefect flows yesterday, and I am interested in the scheduling feature. Is it possible to trigger the execution of a Flow based on: 1. update in the data csv file 2. new data in the database, etc?
z

Zheng Cheng

06/27/2022, 11:43 AM
also new beginner here (not prefect employee) I think you can add web hook of some sort. send HTTP request to trigger Prefect flow run
when “things” happen, send a http request with some parameter to Prefect Cloud to trigger a Deployment, it would create a ’flow run” Am I right @Kevin Kho?
k

Kevin Kho

06/27/2022, 3:08 PM
Yes you can. This is for Prefect 1 and this is for Prefect 2. For example, you can connect Lambda to S3 and then run a Flow
z

Zheng Cheng

06/27/2022, 3:18 PM
@Kevin Kho Link for Prefect 2 is 404
k

Kevin Kho

06/27/2022, 3:22 PM
Ah ok will just paste the code:
Copy code
async def run(name: str):
    """
    Create a flow run for the given flow and deployment.

    The flow run will be scheduled for now and an agent must execute it.

    The flow run will not execute until an agent starts.
    """
    async with get_client() as client:
        try:
            deployment = await client.read_deployment_by_name(name)
        except ObjectNotFound:
            exit_with_error(f"Deployment {name!r} not found!")
        flow_run = await client.create_flow_run_from_deployment(deployment.id)

    console.print(f"Created flow run {flow_run.name!r} ({flow_run.id})")
z

Zheng Cheng

06/27/2022, 3:24 PM
no authentication at all? I don’t need to send JWT? is there are doc with more context? how get_client() work. Is this 1.0 or 2.0?
k

Kevin Kho

06/27/2022, 3:25 PM
The client can load authentication
👍 1
z

Zheng Cheng

06/27/2022, 3:54 PM
Got it, client works very well.
12 Views