Skip to content

[BUG] - Job's NextRun time is inaccurate. The job has already run, but NextRun has not been updated to the next scheduled time. #904

@ThinkingXuan

Description

@ThinkingXuan

Describe the bug

Job's NextRun time is inaccurate. The job has already run, but NextRun has not been updated to the next scheduled time.

Multiple Jobs run into this situation when executing simultaneously.

// create a scheduler
	scheduler, err := gocron.NewScheduler()
	if err != nil {
		log.Fatal(err)
	}

	// add a job to the scheduler
	job1, err := scheduler.NewJob(
		gocron.DurationJob(1*time.Minute),
		gocron.NewTask(func() {
			log.Println("Job executed start")
			time.Sleep(10 * time.Second)
			log.Println("Job executed")
		}),
		gocron.WithName("example-job"),
		gocron.WithTags("important"),
	)

	// add a job to the scheduler
	job2, err := scheduler.NewJob(
		gocron.DurationJob(2*time.Minute),
		gocron.NewTask(func() {
			log.Println("Job executed start")
			time.Sleep(10 * time.Second)
			log.Println("Job executed")
		}),
		gocron.WithName("example-job"),
		gocron.WithTags("important"),
	)

	job3, err := scheduler.NewJob(
		gocron.DurationJob(3*time.Minute),
		gocron.NewTask(func() {
			log.Println("Job executed start")
			time.Sleep(10 * time.Second)
			log.Println("Job executed")
		}),
		gocron.WithName("example-job"),
		gocron.WithTags("important"),
	)

	job4, err := scheduler.NewJob(
		gocron.DurationJob(4*time.Minute),
		gocron.NewTask(func() {
			log.Println("Job executed start")
			time.Sleep(10 * time.Second)
			log.Println("Job executed")
		}),
		gocron.WithName("example-job"),
		gocron.WithTags("important"),
	)

	if err != nil {
		log.Fatal(err)
	}

	// start the scheduler
	scheduler.Start()

Version

gocorn: v2.18.2
go: 1.24.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions