<@ULVA73B9P> From which version of Prefect can we ...
# ask-marvin
s
@Marvin From which version of Prefect can we start using emit_event()?
m
I'm sorry, but I couldn't find the specific Prefect version that introduced the
emit_event()
function. You may want to check the Prefect change logs or their GitHub repository for this information.
s
@Taylor Curran Any luck with this?
n
emit_event should be available in all recent versions, what version are you on?
s
2.13.1
n
it should be available, from prefect.events import emit_event
👍 1
s
Quick question regarding the same: We are currently deploying the flows locally using the python deploy script. In this case, how do I utilize/include the YAML file while using emit_events?
n
the use of emit_event should have no direct bearing on how you deploy in general, as far as the deployment story goes,
emit_event
just a regular function that you may or may not call in a flow (which happens to create an Event in the workspace indicated by your PREFECT_API_URL) what are you using emit_event for?
s
Context: flow1 -> flow2 Want to trigger flow3 once flow1 reaches completed state without blocking flow2's execution. Currently achieving it via hook & run_deployment(timeout = 0), would like to try out events for the same test case.
n
ah i see - yeah, so theres a couple ways to go about it firstly, flow runs completing is already an Event, so you dont even need to emit an event manually unless you need to distinguish between different "kinds" of completed states for flow 1, a random example being maybe "finished in under 10 mins" --> "prefect.flow-run.CompletedQuickly" event, "finished in over 10 mins" --> "prefect.flow-run.CompletedSlowly" event if all you care about is triggering flow 3 upon completion of flow 1, you just need to re-deploy flow 3 to have a trigger that `expect`s the completion flow 1 event for example here's a prefect.flow-run.Completed event, where the
related
resources are the interesting bit
where i can add a
triggers
section to my deployment definition in
prefect.yaml
like
Copy code
deployments:
- name: your-flow-3-deployment  
  entrypoint: ...
  triggers:
    - enabled: true
      match_related:
        prefect.resource.role: deployment
        prefect.resource.name: the-deployment-name-for-flow-1
      expect:
        - prefect.flow-run.Completed
      parameters:
        param_1: "{{ event }}"
param_1: "{{ event }}"
passes the actual whole event to the flow thats being triggered here, which is an arbitrary choice
s
Do you have any example code that I could refer to especially for this one "_if all you care about is triggering flow 3 upon completion of flow 1, you just need to re-deploy flow 3 to have a trigger that `expect`s the completion flow 1 event_".
n
thats the yaml trigger just above here, that would be like your flow 3 in your
prefect.yaml
. you'd replace
Copy code
match_related:
        prefect.resource.role: deployment
        prefect.resource.name: the-deployment-name-for-flow-1
👀 1
oops i meant flow 1 there, since you're expecting a completion of flow 1 to trigger flow 3 right? if you can find a
Flow run Completed
event for flow 1 in your event feed, i could help you build your trigger like i have above
s
As I mentioned earlier, my python_deploy.py script & folder structure looks something like this:
I'm finding it hard to understand how the YAML file is picked up by the deploy script.
n
how do I utilize/include the YAML file while using emit_events?
when i heard this i thought you meant you were switching from python deploy script to
prefect.yaml
build_from_flow
should be thought of as being deprecated (it is not literally deprecated but will be). it is for building deployments run by agents and it is not meant to be used with
prefect.yaml
you can fully define all your deployments with a
prefect.yaml
, but if you really want python deployment definitions, you can ask @Taylor Curran about .deploy, which does all the things build_from_flow does, but for workers (modern recommendation)
thank you 1
panda dancing 1
in case its helpful, an example monorepo using
prefect.yaml
to define deployments
thank you 1