Does anybody have flows that act as infinite loops...
# ask-community
c
Does anybody have flows that act as infinite loops running the same tasks again and again instead of scheduling a flow to run every few seconds? Just wondering if there’s any downside to doing that vs. scheduling it.
a
ha! you're speaking @Chris White's love language. he's traveling so might be slow to respond but this has really been on his mind recently
c
Haha good to know. It seems to me that an infinite loop seems to be easier on the Prefect API and thus better with resources on the worker side. It’s especially useful when I don’t know the exact time the flow run will take to execute, so a set schedule doesn’t work out that well since it sometimes causes multiple flow runs to be Running at once, leading to backlogs. Running it sequentially in a “while: True” loop just starts the next iteration whenever the previous one finishes, so timing isn’t an issue.
a
yeah we've put a ton of thought recently in things like idempotency and caching so that your have tasks run in a big ole loop forever - cached - and then you can externally invalidate that cache if you want to have it do the real work
c
Haha yes! It’s a valid pattern, I think the only catch is that the assumption that flows terminate in some reasonable timeframe is baked into the UI in a lot of ways, so you might experience friction in that regard. In this case the flow is acting kind of like it’s own worker, and I wonder if there’s a way we could support that in a first class way 🧐
Could be worth starting a discussion on GitHub on the topic of “long running flows”