Skip to content

feat: Add option to calculate intervals from job completion time for interval-based scheduling (fixes #565)#884

Merged
JohnRoesler merged 2 commits intogo-co-op:v2from
iyashjayesh:feat/565-interval-timing
Oct 22, 2025
Merged

feat: Add option to calculate intervals from job completion time for interval-based scheduling (fixes #565)#884
JohnRoesler merged 2 commits intogo-co-op:v2from
iyashjayesh:feat/565-interval-timing

Conversation

@iyashjayesh
Copy link
Contributor

Summary

Adds a new job option WithIntervalFromCompletion() that changes how the next run time is calculated for interval-based jobs. Instead of calculating from the scheduled start time (default), jobs can now calculate from their completion time, ensuring consistent rest periods between executions.

Resolves #565
Related to discussion #564

Problem

Currently, jobs scheduled with DurationJob calculate their next run time from the scheduled start time, not from when they complete. This causes inconsistent rest periods when execution times vary.

Usage Example

s, _ := gocron.NewScheduler()

s.NewJob(
    gocron.DurationJob(5*time.Minute),
    gocron.NewTask(func() {
          // job task
    }),
    gocron.WithIntervalFromCompletion(), 
)

s.Start()

Did you document any new/modified functionality?

Copy link
Contributor

@JohnRoesler JohnRoesler left a comment

Choose a reason for hiding this comment

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

Fantastic work here - I appreciate the thorough testing and documentation 👍

@JohnRoesler JohnRoesler merged commit 3ee53e0 into go-co-op:v2 Oct 22, 2025
3 checks passed
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.

[FEATURE] - Interval job to optionally include job duration

2 participants