Audit and fix scheduling and state management#15
Merged
luke-lombardi merged 11 commits intoNov 26, 2025
Conversation
This commit introduces several improvements:
- **Enhanced `LoopContext.sleep_for` and `LoopContext.sleep_until`**:
- Added docstrings explaining functionality, arguments, and potential errors.
- Implemented validation for sleep durations and timestamps to prevent invalid values.
- `sleep_for` now raises a `ValueError` if the duration is not positive.
- `sleep_until` now raises a `ValueError` if the timestamp is in the past.
- **State Management Updates**:
- **`LoopEvent` and `LoopState`**:
- Renamed `to_json` methods to `to_dict` for clarity and consistency.
- Added `to_string` methods for JSON serialization.
- Kept `to_json` as a deprecated alias for `to_dict` for backward compatibility.
- Changed `created_at` type in `LoopState` from `int` to `float` for better precision.
- **`RedisStateManager`**:
- Improved `_run_wake_monitoring` with better error handling and logging.
- Modified `set_wake_time` to use milliseconds (`px`) for Redis TTL, allowing for more precise wake-up scheduling.
- Updated `set_wake_time` to use the full wake key in `srem` for consistency.
- Added a docstring to `has_claim` for better understanding.
- **`S3StateManager`**:
- Explicitly raised `NotImplementedError` in `set_wake_time` with a clear message indicating that S3 does not support wake time scheduling.
- Added a private `_delete_object` method.
- **Utility Function Update**:
- **`infer_application_path`**:
- Updated the function signature to accept `app_instance` instead of `self`.
- Improved the docstring to clarify its purpose and arguments.
- Enhanced introspection logic to correctly identify the application instance.
Co-authored-by: luke <luke@smartshare.io>
|
Cursor Agent can help with this pull request. Just |
Co-authored-by: luke <luke@smartshare.io>
Co-authored-by: luke <luke@smartshare.io>
Co-authored-by: luke <luke@smartshare.io>
Co-authored-by: luke <luke@smartshare.io>
This commit replaces fakeredis with a real Redis instance for scheduling tests. It also updates the CI to include a Redis service and modifies the Makefile to support starting/stopping a local Redis instance. The integration tests have been removed as they are now covered by the refactored unit tests. Co-authored-by: luke <luke@smartshare.io>
Co-authored-by: luke <luke@smartshare.io>
This commit refactors the state management system, particularly for Redis, to enhance reliability and simplify the code. It also updates documentation and tests for better clarity and robustness. Co-authored-by: luke <luke@smartshare.io>
Add stop method to RedisStateManager for graceful shutdown of the wake monitoring thread. Update tests to use unique app names and ensure proper cleanup. Add pytest-asyncio and ruff to dev dependencies. Update fastapi version to 0.115.14. Update fastloop version to 0.1.71. Co-authored-by: luke <luke@smartshare.io>
Co-authored-by: luke <luke@smartshare.io>
Co-authored-by: luke <luke@smartshare.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix scheduling bugs and improve state management for reliable wake-up times and overall code quality.
The primary goal was to ensure reliable
sleep_forandsleep_untilfunctionality. This involved fixing a critical bug where sub-second sleep durations were lost due to integer casting in Redis TTLs, and resolving an inconsistency in how wake keys were managed in the Redis wake index, which led to orphaned entries. Additionally, various state management inconsistencies and code quality issues were addressed across the codebase.