-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscribe to state changes in wait_for_flow_run #17243
Conversation
src/prefect/flow_runs.py
Outdated
@@ -116,15 +118,30 @@ async def main(num_runs: int): | |||
""" | |||
assert client is not None, "Client injection failed" | |||
logger = get_logger() | |||
|
|||
flow_run = await client.read_flow_run(flow_run_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know that this is even necessary to check before we enter the subscriber iterable, maybe we can remove this whole block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I think to avoid any missed events / race conditions due to the time it takes to make this call, we should check for a final state immediately after entering the subscriber (but before the async for
) , but yeah we should be able to remove that first one outside the subscriber
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, let me know if the new version is what you had in mind
CodSpeed Performance ReportMerging #17243 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR @bnaul 🎉
a couple comments but I really like the idea of the change. For later, I think there's some fun nuance with the eventual goal of interleaving logs and events since I think we'll need 2 async iterators (events come from websocket, logs from REST)
happy to hash out details in the issue you opened!
src/prefect/flow_runs.py
Outdated
@@ -116,15 +118,30 @@ async def main(num_runs: int): | |||
""" | |||
assert client is not None, "Client injection failed" | |||
logger = get_logger() | |||
|
|||
flow_run = await client.read_flow_run(flow_run_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I think to avoid any missed events / race conditions due to the time it takes to make this call, we should check for a final state immediately after entering the subscriber (but before the async for
) , but yeah we should be able to remove that first one outside the subscriber
@@ -54,7 +56,6 @@ | |||
async def wait_for_flow_run( | |||
flow_run_id: UUID, | |||
timeout: int | None = 10800, | |||
poll_interval: int = 5, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically this is a breaking change (unfortunately since its likely infrequently used) so I think we should keep it and if a non-default value is provided we log some warning to say it has no effect and will be removed in a future release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, that's actually how I had it before so I just reverted 53a1242
Yeah I did not realize that until digging into the subscriber stuff a bit more...I think this is a nice little change on its own but the full goal of #17228 is a little more than I initially bargained for 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet! this LGTM, thanks for the PR @bnaul 🎉
for reference, I'll put a WIP of the interleaving stuff that more or less does the right thing in the original issue in case you do end up wanting to tackle that
@bnaul oh also, please run |
thanks @zzstoatzz, believe those are both taken care of! |
Sort of a precursor to #17228; the current implementation polls for state changes (and logs on each poll, even when the state has not changed). As a half step towards also streaming other events / logs, I wanted to start by just swapping the polling for an event subscriber. The result is almost the same except for de-duping the repeated logs from the same state.
I went back and forth on whether to remove the
poll_interval
/watch_interval
argument or warn that it's deprecated or just have it do nothing, I'm not sure if you have a specific policy on little CLI changes like that but either seems fine to me.Before:
After: