fix: add scheduler daemon mode to handle missed cron jobs after system wake-from-sleep#1180
Open
Jefsky wants to merge 1 commit into
Open
fix: add scheduler daemon mode to handle missed cron jobs after system wake-from-sleep#1180Jefsky wants to merge 1 commit into
Jefsky wants to merge 1 commit into
Conversation
…m wake-from-sleep Problem: When running in Docker (supercronic mode), if the host system enters sleep/hibernation, supercronic does not fire cron jobs that were scheduled during the sleep period. Users must manually restart the container to trigger execution. Root cause: supercronic (like all cron implementations) only fires jobs at their exact scheduled time. Jobs scheduled while the system is asleep are simply skipped with no catch-up mechanism. Fix: Add a new RUN_MODE=daemon mode that replaces supercronic with a persistent Python scheduler daemon (docker/scheduler_daemon.py). The daemon: 1. Reads the CRON_SCHEDULE expression and checks every 60 seconds 2. Runs TrendRadar at scheduled times with proper deduplication 3. On startup, checks if any scheduled runs were missed during system sleep (up to 2 hours back) and runs catch-up immediately 4. During runtime, detects missed runs after wake events and catches up 5. Works alongside the existing Web server (started in parallel) Usage: Set RUN_MODE=daemon (instead of default 'cron') in docker-compose. Fixes sansan0#893
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.
Problem
When running TrendRadar in Docker with
RUN_MODE=cron(the default), scheduled tasks rely on supercronic to firepython -m trendradarat the configuredCRON_SCHEDULEtimes. This works fine as long as the host system stays awake.If the host enters sleep/hibernation (laptop lid close, standby, etc.), supercronic does not fire jobs that were scheduled during the sleep period. When the system wakes up:
docker restartthe containerThis affects users on laptops (Mac/Windows/Linux) who use Docker Desktop or put their machines to sleep overnight.
Root Cause
supercronic (like all standard cron implementations) only fires jobs at their exact scheduled moment. There is no catch-up mechanism for missed jobs — the scheduling event is ephemeral.
Fix
Add a new
RUN_MODE=daemonmode that replaces supercronic with a lightweight persistent Python scheduler daemon (docker/scheduler_daemon.py).The daemon:
0 11,15 * * *)How to use
Set the environment variable in your docker-compose.yml or Docker run command:
Testing
RUN_MODE=daemonandCRON_SCHEDULE=0 11,15 * * *Fixes #893