There was a question on Wednesday about capturing ...
# pacc-oct-16-17-2024
j
There was a question on Wednesday about capturing events. Got a code snippet in the 🧵
Copy code
# get_events_subscriber takes an EventFilter as input.
# creates an infinite loop so you'll need to add your own logic to exit it once you've seen the events you're looking for

from prefect.events import get_events_subscriber
from prefect import flow
import asyncio


@flow(log_prints=True)
async def subs():
    seen_events = set()
    async with get_events_subscriber() as subscriber:
        async for event in subscriber:
            print(f"📬 Received event {event.event!r}")
            seen_events.add(event.event.event)
            if len(seen_events) > 5:
                break


if __name__ == "__main__":
    asyncio.run(subs())
Here’s a repo that shows filtering with it.
m
Am I reading the docs right - webhooks are only available with Prefect Cloud? No way to use these with self-hosted Prefect?
j
That’s correct, @MikeT. They are only available on Prefect Cloud now.
m
Okay, thanks for confirming.