Florian Giroud
08/13/2025, 10:01 PMemit_event
, with a deployment trigger for another flow, but the flow got triggered 3 times, do you know what can be causing this ?Marvin
08/13/2025, 10:01 PMMarvin
08/13/2025, 10:06 PMfrom prefect import get_run_context
from prefect.events import emit_event
def emit_once(...):
ctx = get_run_context()
# Only on first attempt
if not getattr(ctx, "task_run", None) or ctx.task_run.attempt == 1:
emit_event(event="my.custom.event", resource={"prefect.resource.id": "something"})
- If mapping/loops are the cause, move emit_event outside the mapped task or guard with a flag so it runs once.
- If the trigger is fanning out:
- Disable “run for each match” (if enabled), or
- Tighten conditions on resource/related filters so only one thing matches your event.
- If you have overlapping triggers, consolidate them or add mutually exclusive conditions.
- As a safety net, set a deployment concurrency limit with a “cancel oldest” policy to avoid multiple active runs.
If you can share:
- Your trigger definition (screenshot/text of the conditions, and whether “run for each” is on)
- Where emit_event is called (inside a loop/map? any retries?)
- A couple of event_ids from the Event feed
…I can point to the exact root cause instead of playing guess-the-trigger.
Docs, in case you enjoy light bedtime reading:
- Event triggers: Event triggers concepts
- Creating deployment triggers: How to create deployment triggers