-
Notifications
You must be signed in to change notification settings - Fork 392
[proposal] make run flows cancellable if coroutine scope is cancelled #2488
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
base: main
Are you sure you want to change the base?
Conversation
logger.info("Flow cancelled, skipping command...") | ||
onCommandSkipped(index, command) | ||
return@forEachIndexed | ||
} |
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.
Let's say if coroutine context is cancelled where should we be releasing resources that got acquired during execution?
There are bunch already that could be acquired: There is insights listener, leaveScope on jsEngine, there is global screenRecording field which would have risk of just keep running.
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.
Let's say if coroutine context is cancelled where should we be releasing resources that got acquired during execution?
on the same place they get released without cancellation?
is there anything on this PR not being released with this change?
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 see some funkiness with the jsEngine thing being a lateinit. I'll keep it being initialized even if the routine is cancelled to avoid some unexpected behavior
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.
verified that screenrecording.close will be called regardless of cancellation, so that one seems safe?
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.
Direction looks great, I'm trying to think what would be best way to add a test for this to ensure, cancelling coroutine:
- Skips rest of commands
- Expect to release resources which were acquired
|
||
commands | ||
.forEachIndexed { index, command -> | ||
if (!coroutineContext.isActive) { |
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'm thinking how this should look like for cli, should there be any controls there? I believe not useful, because users usually press control + c to break from flows.
Although I'm not sure about CI
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.
ctrl+c kills the entire Java process, so it's not gonna impact any of this. Coroutine cancellation is for when you have a process still running and you want to cancel it
7163212
to
924909b
Compare
The goal here is to make a Maestro Orchestra coroutine-cancellable - if the context where it's running is cancelled, it'll skip heavy setup steps (eg initializing the js engine). It'll still go through all the commands on the flow, but marking them all as SKIPPED instead of executing them.