Sanjeev
12/11/2023, 2:42 PMNate
12/11/2023, 2:53 PMMarvin
12/11/2023, 2:54 PMdeployment.yaml
file, you can edit the file to set the default parameter values before applying the deployment using the prefect deployment apply
command. However, be cautious not to edit the section of the YAML file that includes the "DO NOT EDIT" comment, as that part is autogenerated and should not be manually changed.
If you want the Prefect API to enforce the parameter schema, you can set enforce_parameter_schema
to true
to ensure that the parameter values passed to a flow run are verified against the schema defined by the parameter_openapi_schema
.
You can read more about this in the Prefect documentation: Deployments.Nate
12/11/2023, 2:55 PMprefect.yaml
instead of deployment.yaml
. you can also pass params to an adhoc deployment run with run_deployment(..., parameters={...{})
Sanjeev
12/11/2023, 4:20 PMactions
section, run-deployment
is the only action that related closely to running a flow. Is there something specific to flow? like run-flow
? Or does this apply for flows too? If the latter is the case, can I mention the flow-id
as deployment-id
?Nate
12/11/2023, 4:23 PMSanjeev
12/11/2023, 4:25 PMarchiving
flow elevated to deployment. But, I have multiple flows that will resuse this deployement by changing the path
. In case of Deployment how do I pass the dynamic path parameter via the automation?Nate
12/11/2023, 4:27 PMSanjeev
12/11/2023, 4:30 PMpath
refers to a variable that contains the path to the files the needs to be archived. I need to pass this dynamic path
variable to a deployment via automation triggers. I hope this clarifies.Nate
12/11/2023, 4:36 PMMarvin
12/11/2023, 4:37 PMprefect.yaml
, you would include triggers with templated parameters that can extract values from events. Here is an example of how you can set this up:
Suppose you have a YAML configuration file named prefect.yaml
for your deployment trigger. You would include a section that looks something like this:
yaml
flow.py:decorated_fn
work_pool:
name: my-process-pool
triggers:
- enabled: true
match:
prefect.resource.id: my.external.resource
expect:
- external.resource.pinged
parameters:
param_1: "{{ event }}"
In this example:
- `enabled`: This should be set to true
to enable the trigger.
- `match`: A dictionary specifying the matching criteria for the events that should trigger the automation. prefect.resource.id
is compared with the event source identifier.
- `expect`: A list of event types that this trigger expects to react to, such as 'external.resource.pinged'
.
- `parameters`: A dictionary where the keys correspond to the parameter names expected by the flow, and the values are templated to contain the event payload.
At deployment time, this configuration will create a linked automation that is triggered by events matching your chosen criteria and will pass the templated event as a parameter to the deployment's flow run.
You can also provide triggers from the CLI when deploying, for example:
bash
prefect deploy -n test-deployment --trigger triggers.yaml
This command references an external triggers.yaml
file, which can house multiple trigger definitions.
Suppose the triggers.yaml
file looks like this:
yaml
triggers:
- enabled: true
match:
prefect.resource.id: my.external.resource
expect:
- external.resource.pinged
parameters:
param_1: "{{ event }}"
- enabled: true
match:
prefect.resource.id: my.other.external.resource
expect:
- some.other.event
parameters:
param_1: "{{ event }}"
This approach allows the definition of multiple triggers within the same file, each with potentially different match and expect criteria, and unique parameter templating based on the incoming event data.
For more information on automatons and triggers, you can visit the Prefect documentation on Automations.Sanjeev
12/11/2023, 4:39 PMNate
12/11/2023, 4:41 PMNate
12/11/2023, 4:41 PMSanjeev
12/11/2023, 4:42 PMNate
12/11/2023, 4:44 PMSanjeev
12/11/2023, 4:44 PMSanjeev
12/11/2023, 4:48 PMparam_1
point towards the name of the event?Nate
12/11/2023, 5:00 PMIn the example provided by marvin, does thethats like the whole event, this is jinja so you can do dot access on that, @Marvin example plspoint towards the name of the event?param_1
Marvin
12/11/2023, 5:01 PMyaml
triggers:
- enabled: true
match:
prefect.resource.id: my.external.resource
expect:
- external.resource.pinged
parameters:
# Accessing a top-level property from the event
param_top_level: "{{ event.property_name }}"
# Accessing a nested property from the event
param_nested: "{{ event.nested.property_name }}"
This example illustrates two ways to access the event data:
1. `param_top_level`: Accesses a top-level property of the event. Replace property_name
with the actual name of the property in the event you want to access.
2. `param_nested`: Accesses a nested property of the event. Replace nested.property_name
with the actual path to the nested property from the event you want to access.
It is important to note that when using attribute-style access (event.property_name
), it only works if the event property is a valid Python identifier. If the property name includes characters that are not valid in Python identifiers (like hyphens), you should use the index-style access (event['property-name']
).
For more complex scenarios, you can use the full power of Jinja templating within Prefect to manipulate the event data as needed for passing it as parameters to your flows.
For additional details on how to use webhooks and Jinja templates in Prefect, you can check out the Prefect documentation on Webhooks.