Add support for simultaneous runs of Script helper - Part 2#32442
Add support for simultaneous runs of Script helper - Part 2#32442balloob merged 15 commits intohome-assistant:devfrom
Conversation
|
I've made the other changes already requested and tested them. I'll go ahead and make another commit so they can be looked over while we decide what to do about stopping/restarting invoked scripts. |
Call change listener immediately if its a callback
- Remove background/blocking _ScriptRun subclasses which are no longer needed.
This makes restart mode behavior consistent with parallel & queue modes.
- Call all script services (except script.turn_off) with no time limit. - Fix handling of lock in _QueuedScriptRun and add comments to make it clearer how this code works.
- Move cancel shielding "up" from _ScriptRun.async_run to Script.async_run (and apply to new style scripts only.) This makes sure Script class also properly handles cancellation which it wasn't doing before. - In _ScriptRun._async_call_service_step, instead of using script.turn_off service, just cancel service call and let it handle the cancellation accordingly.
|
FYI, I did a rebase that I need to force push to resolve the conflicts from your PR. |
|
This looks good ! We can merge this after conflicts resolved. Conflicts caused by me moving some constants to Let's do the unshielding of the service call in core.py in a future PR. |
|
I did some ad hoc testing and found a bug in the turn off sequence initiated by a cancellation. (Turning off was originally done via a service so I had overlooked this one.) I want to commit that fix, then do a lot more testing (both with additional formal tests as well as ad hoc) before we merge this change. Give me at least a few more days. Regarding removing the shield from |
|
Force push required due to rebase. See last commit for changes since last review. |
|
I'd still like to do more testing, possibly adding more formal tests, before this PR is merged. |
- Don't log asyncio.CancelledError exceptions. - Make change_listener a public attribute. - Test overhaul - Parametrize tests. - Use common test functions. - Mock timeout so tests don't need to wait for real time to elapse. - Add common function for waiting for script action step.
|
Assuming the tests pass (they did locally), and you don't find any other issues, then I think we can put this one to bed and I'll start working on the |
|
Booooooooooom 🎉 |
Proposed change
This is a follow-on to #31937.
While working to use those changes in the script integration a few bugs were discovered. Also it became clear that a slight change of direction was needed regarding how to configure/handle long running scripts. Lastly a new
queuemode was added which can be very helpful in certain scenarios (especially for automation action sequences.)The changes were broken up into several, smaller commits to help make the review process easier.
New Script helper option
script_mode
async_runcalled) while previous run has not yet completed.errorRaise an exceptionignoreReturn without doing anything (previous run continues as-is)legacyImplements previous behavior, which is to return when done, or when suspended bydelayorwait_template, whichever comes first. This is the defaultparallelStart run in new taskqueueStart new run when previous runs have completedrestartStop previous run before starting new runNew script.turn_on service parameter
Background/blocking behavior is now controlled by the
script.turn_onservice. The default (which also applies when calling a script "directly" --script.abc-- or via thescript.toggleservice) is to be fully blocking. To run a script in the "background" a newblockingparameter to thescript.turn_onservice has been defined:Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: