-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Prevent time pattern reschedule if cancelled during job execution #117879
Prevent time pattern reschedule if cancelled during job execution #117879
Conversation
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.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
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.
Good find. 👍 Please add a test case for this change.
An alternate fix that wouldn't require a new flag is to move That's probably more efficient as well for the common case as it's going to be very rare that the timer handler is cancelled from the job. |
Thank you for detailing out the execution flow, it made reviewing this and understanding the problem nearly immediate. |
I've given it some thought, but I think it could cause problems. |
Does |
I don't think it could be an issue because we already fetch utcnow to calculate the next time before the job is run. If this was a problem it would already be firing the next one right away. The job can't block and will finish synchronously as otherwise it would block the event loop. This is also how core/homeassistant/helpers/event.py Line 1608 in be6598e
|
Since we are likely to ship 2024.5.5 soon, we can push this to 2024.6.x if its not ready by than. Its not a blocker as its been a problem for a while |
I will remove the flag and move |
0291ed7
to
58bafa5
Compare
Thanks for the insight and the quick review! |
Thanks @swoga |
Proposed change
An automation that is triggered via a time entity creates a scheduled job for triggering on the next due date.
However, after triggering, a new job is always scheduled for the next execution.
This becomes a problem if the value of the entity is changed during the execution of the automation.
input_datetime.test
core/homeassistant/helpers/event.py
Line 1779 in f21226d
input_datetime.set_datetime
forinput_datetime.test
, which leads to cancellationcore/homeassistant/helpers/event.py
Line 1789 in f21226d
core/homeassistant/helpers/event.py
Line 1782 in f21226d
Type of change
Additional information
Checklist
ruff format 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
.To help with the load of incoming pull requests: