feat: [#690] enhance schedule method and resolve issue with second-level cron jobs on OnOneServer#1052
feat: [#690] enhance schedule method and resolve issue with second-level cron jobs on OnOneServer#1052
Conversation
…vel cron jobs on OnOneServer
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the scheduling functionality by introducing support for second-level cron jobs along with new scheduling methods such as TwiceDaily, EverySecond, and various interval-based scheduling options, while also updating the event interface accordingly.
- Added new scheduling methods and corresponding tests in schedule/event_test.go.
- Updated cron expression generation logic and introduced helper functions (simplifyRanges, formatRange) in schedule/event.go.
- Adjusted lock key generation in schedule/application.go to handle second-level cron expressions.
- Updated the schedule interface in contracts/schedule/event.go to include the new methods.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| schedule/event_test.go | New tests for extended scheduling methods including second-level cron. |
| schedule/event.go | New scheduling methods and helper functions for cron expression generation. |
| schedule/application.go | Adapted job locking logic to support second-level cron formatting. |
| contracts/schedule/event.go | Updated interface with new scheduling methods. |
| if event.IsOnOneServer() && event.GetName() != "" { | ||
| if app.cache.Lock(event.GetName()+carbon.Now().Format("Hi"), 1*time.Hour).Get() { | ||
| keySuffix := carbon.Now().Format("Hi") | ||
| if segments := strings.Split(event.GetCron(), " "); len(segments) == 6 { |
There was a problem hiding this comment.
Consider adding a comment here to explain why keySuffix is changed to use 'His' when a 6-segment cron expression is detected, as this behavior is critical to ensuring unique lock identifiers for second-level jobs.
| func (receiver *Event) DelayIfStillRunning() schedule.Event { | ||
| receiver.delayIfStillRunning = true | ||
| // TwiceDaily schedule the event to run twice a day,default at 1:00 and 13:00. | ||
| func (r *Event) TwiceDaily(hours ...int) schedule.Event { |
There was a problem hiding this comment.
[nitpick] Please clarify in the function's comment that the default times of 1:00 and 13:00 are used when no parameters are provided, ensuring the documentation matches the behavior verified in tests.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1052 +/- ##
==========================================
+ Coverage 71.07% 71.25% +0.18%
==========================================
Files 178 178
Lines 12446 12546 +100
==========================================
+ Hits 8846 8940 +94
- Misses 3211 3215 +4
- Partials 389 391 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📑 Description
Closes goravel/goravel#690
✅ Checks