<@ULVA73B9P> Using Prefect and the Prefect.yaml fi...
# ask-marvin
v
@Marvin Using Prefect and the Prefect.yaml file, how do I deploy a flow that should only be triggered manually (no schedule)? Also, this flow receives an argument and I want Prefect to prompt the user for this parameter when the flow is triggered
m
To deploy a flow in Prefect 3.x that should only be triggered manually (without a schedule) and prompts the user for a parameter, you can follow these steps: 1. Define the Flow and Parameters: Use the
@flow
decorator to define your flow and specify any parameters it requires. Prefect will handle prompting for these parameters when you trigger the flow.
Copy code
python
   from prefect import flow

   @flow
   def my_flow(param: str):
       print(f"Received parameter: {param}")
2. Configure
prefect.yaml
: In your
prefect.yaml
file, specify the deployment without a schedule. Prefect allows you to define triggers in the
prefect.yaml
, but since you want to trigger manually, you won't set any triggers or schedules.
Copy code
yaml
   deployments:
     - name: my-manual-deployment
       flow: my_flow
       parameters:
         param: null  # This will prompt for the parameter when triggered
3. Deploy the Flow: Use the CLI to deploy the flow with the specified configuration.
Copy code
bash
   prefect deploy -n my-manual-deployment
4. Trigger the Flow Manually: You can run the deployment manually from the Prefect UI or CLI. Prefect will prompt for the
param
value when you trigger the flow. For more detailed guidance, refer to the Prefect documentation. This approach ensures that the flow is only run when manually triggered, and it will prompt for any required parameters at runtime.
v
@Marvin what about Prefect 2.X?
m
In Prefect 2.x, deploying a flow that should only be triggered manually and prompts for a parameter can be achieved as follows: 1. Define the Flow with Parameters: As in Prefect 3.x, use the
@flow
decorator to define your flow and specify any parameters it requires.
Copy code
python
   from prefect import flow

   @flow
   def my_flow(param: str):
       print(f"Received parameter: {param}")
2. Configure
deployment.yaml
: In Prefect 2.x, you'll use a
deployment.yaml
file to specify the deployment. Set the parameters to prompt for them during runtime by leaving them unset or set to
null
.
Copy code
yaml
   name: my-manual-deployment
   flow_name: my_flow
   parameters:
     param: null  # This will prompt for the parameter when triggered
3. Deploy the Flow: Use the CLI to deploy the flow using the configuration in
deployment.yaml
.
Copy code
bash
   prefect deployment create -n my-manual-deployment
4. Trigger the Flow Manually: You can run the deployment manually from the Prefect UI or CLI. When you trigger the flow, Prefect will prompt for the
param
value. For more details, refer to the Prefect 2.x documentation. This setup will ensure that the flow is only executed manually and prompts for the required parameters when triggered.