Skip to content

fix(cron): avoid polling running jobs and rearm after completion - #1023

Draft
yunyv wants to merge 4 commits into
modelscope:mainfrom
yunyv:fix/cron-wake-rearm
Draft

yunyv wants to merge 4 commits into
modelscope:mainfrom
yunyv:fix/cron-wake-rearm

Conversation

@yunyv

@yunyv yunyv commented Oct 24, 2026

Copy link
Copy Markdown

Change Summary

Running jobs retain their overdue next_run_at until execution finishes. The scheduler excludes them from dispatch but still uses them to select its next wake, causing repeated 0.1-second polls when there is nothing dispatchable instead of using the default 60-second polling interval. Completed jobs with an overdue timestamp can select the same unnecessary wake.

Exclude running and completed jobs from wake selection. Recompute the timer after persisting a result in both execution paths, so short recurring schedules are not delayed until the normal polling deadline.

Tests cover inactive states, future jobs, recovery transitions, concurrent running jobs, recurring completion, and shutdown. With normal package imports, the final tests produce 8 failures and 103 passes on the original implementation, then 111 passes with this patch.

Validation: python -m pytest tests/cron -q, changed-file pre-commit hooks, pip check, and git diff --check pass. Full pre-commit run --all-files was attempted and fails on existing repository lint/style issues, including .dev_scripts/webui/oss_distribution.py:140 and ms_agent/config/skills_manager.py:61. Unrelated automatic formatting was reverted. The full repository test suite was not run.

Pause-during-execution state preservation is handled separately in #1022 and is not included here. No CPU savings were measured.

Prepared and tested with AI assistance.

Related issue number

None. Found while inspecting scheduler wake selection; this does not overlap #1013's interval timezone normalization.

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check. Both ran; existing full-repository failures are described above.
  • Documentation reflects the changes where applicable (internal scheduling behavior; no new command or configuration)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant