Skip to content

feat: [#690] enhance schedule method and resolve issue with second-level cron jobs on OnOneServer#1052

Merged
almas-x merged 2 commits intomasterfrom
almas/#690
May 29, 2025
Merged

feat: [#690] enhance schedule method and resolve issue with second-level cron jobs on OnOneServer#1052
almas-x merged 2 commits intomasterfrom
almas/#690

Conversation

@almas-x
Copy link
Contributor

@almas-x almas-x commented May 28, 2025

📑 Description

Closes goravel/goravel#690

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings May 28, 2025 08:44
@almas-x almas-x requested a review from a team as a code owner May 28, 2025 08:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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 {
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 96.64804% with 6 lines in your changes missing coverage. Please review.

Project coverage is 71.25%. Comparing base (28d87a5) to head (89f33de).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
schedule/event.go 96.55% 4 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good, LGTM

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good 👍

@almas-x almas-x merged commit cb187f0 into master May 29, 2025
14 checks passed
@almas-x almas-x deleted the almas/#690 branch May 29, 2025 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include support for seconds timer in Schedule

4 participants