feat(cron): add min_interval_seconds config to prevent excessive cron scheduling#1718
Open
darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
Open
feat(cron): add min_interval_seconds config to prevent excessive cron scheduling#1718darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
Conversation
- Add MinIntervalSeconds field to CronToolsConfig (default: 60 seconds) - Add environment variable PICOCLAW_TOOLS_CRON_MIN_INTERVAL_SECONDS - Implement validateMinInterval() to check schedule intervals - For 'every' type: directly compare every_seconds with minimum - For 'cron' type: calculate next two ticks interval using gronx - Value 0 disables the check - Add comprehensive test cases Closes sipeed#1655
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.
Summary
This PR implements the feature requested in #1655 to add a minimum interval configuration for cron scheduling to prevent excessive task scheduling.
Changes
Configuration
MinIntervalSecondsfield toCronToolsConfigstructPICOCLAW_TOOLS_CRON_MIN_INTERVAL_SECONDSValidation Logic
validateMinInterval()function to check schedule intervalseverytype: directly comparesevery_secondswith minimumcrontype: calculates the interval between next two ticks using gronx libraryattype) are not affectedError Messages
Tests
Added comprehensive test cases in
pkg/tools/cron_test.go:TestCronTool_MinIntervalSeconds: validates default 60-second minimumTestCronTool_MinIntervalSecondsDisabled: validates that 0 disables the checkTestCronTool_MinIntervalSecondsCron: validates cron expression interval checkingTestCronTool_AtSecondsNotAffected: validates one-time schedules are not affectedTestCronTool_MinIntervalSecondsCustom: validates custom minimum valuesTestCronTool_MinIntervalSecondsNegative: validates negative values use defaultRelated Issue
Closes #1655