-
-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2 daily job seems to execute in an infinite loop #634
Labels
bug
Something isn't working
Comments
1 task
2 tasks
@USA-RedDragon Thanks for the call out! v2.0.1 has the fix. package main
import (
"fmt"
"log"
"time"
"github.com/go-co-op/gocron/v2"
)
func main() {
scheduler, err := gocron.NewScheduler()
if err != nil {
log.Fatalf("Failed to create scheduler: %s", err)
}
job, err := scheduler.NewJob(
gocron.DailyJob(
1,
gocron.NewAtTimes(
gocron.NewAtTime(0, 0, 0),
),
),
gocron.NewTask(func() {
fmt.Printf("Task ran!\n")
}),
)
if err != nil {
log.Fatalf("Failed to schedule job: %s", err)
}
scheduler.Start()
time.Sleep(1 * time.Second)
nextRun, err := job.NextRun()
if err != nil {
log.Printf("failed to get nextRun: %s\n", err)
}
log.Printf("job next run: %s\n", nextRun)
err = scheduler.StopJobs()
if err != nil {
log.Fatalf("Failed to stop jobs: %s", err)
}
err = scheduler.Shutdown()
if err != nil {
log.Fatalf("Failed to shutdown scheduler: %s", err)
}
} |
Thanks for the fast fix! |
Sometimes the timing just lines up perfectly. I should be careful though, I don't want to set an expectation that I always fix things that fast! 😂 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When starting the scheduler after adding a daily job it seems to execute in an infinite loop. A minimal reproduction of the issue is below. I could be "holding it wrong", so to speak too.
Prior to v2 I was using this a daily job like so:
After checking the godocs for DailyJob, it looked like this would be the v2 equivalent:
To Reproduce
I have a minimal reproduction of the issue.
go.mod
entry:github.com/go-co-op/gocron/v2 v2.0.0
Current hashes in
go.sum
:Running this results in about 45k "Task ran!" messages on my machine.
Version
v2.0.0
Yes
Expected behavior
The daily job should execute daily.
Additional context
N/A
The text was updated successfully, but these errors were encountered: