-
Notifications
You must be signed in to change notification settings - Fork 70
refactor: improve handling of intervals in tedge-flows #3801
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
refactor: improve handling of intervals in tedge-flows #3801
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Robot Results
|
| return false; | ||
| } | ||
|
|
||
| let now = Instant::now(); |
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 would pass now as an argument of the method. Having the time externalized makes things easier to test. Using tokio::time mocking helps for unit tests, but is useless for tedge flows test
| /// Note: Caller should check should_execute_interval() before calling this | ||
| pub async fn on_interval( |
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 see pros and cons to externalize or not the check if this call is timely. What are your motivation to move this check out?
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.
For the functions the javascript module exports for tedge-flows to call, my expectation is that the methods on JsScript serve as a lightweight wrapper, doing minimal work beyond calling the function with the provided input. It also feels like a bit of a hack to pretend the function produced no output when it wasn't called at all (or if it entirely doesn't exist).
|
|
||
| /// Check if this script should execute its interval function now | ||
| /// Returns true and updates next_execution if it's time to execute | ||
| pub fn should_execute_interval(&mut self) -> bool { |
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.
It's okay for this PR to have a should_execute_interval function inside the js_script module. However, this abstraction will also be useful for rust-based flow steps as well as for sources producing data at a regular pace.
didier-wenzek
left a comment
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.
Approved. I appreciate the really nice unit test suite.
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
c8b4d1c to
5e68de8
Compare
Proposed changes
Refactor tedge-flows to improve interval handling.
Previously, tedge-flows relied on an exact number of seconds passing to execute an interval, and this had two negative effects:
This PR fixes both of these issues, allowing arbitrary precision intervals that are guaranteed to execute once the interval has elapsed, regardless of how long it takes tedge-flows to inspect the pending tasks. Additionally, the new approach supports the
tokio::timemocking API, so I have added some deterministic integration tests that don't require sleeping whatsoever.Types of changes
Paste Link to the issue
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments