Skip to content
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

[BUG] - WithLimitConcurrentJobs causes jobs not to resume #716

Closed
jmutschler opened this issue Apr 29, 2024 · 4 comments · Fixed by #745
Closed

[BUG] - WithLimitConcurrentJobs causes jobs not to resume #716

jmutschler opened this issue Apr 29, 2024 · 4 comments · Fixed by #745
Labels
bug Something isn't working

Comments

@jmutschler
Copy link

jmutschler commented Apr 29, 2024

Describe the bug

WithLimitConcurrentJobs causes scheduled jobs not to run after StopJobs() then Start()

To Reproduce

func main() {
    s, err := gocron.NewScheduler(
        gocron.WithLimitConcurrentJobs(2, gocron.LimitModeReschedule), // this causes the bug
    )
    if err != nil {
        panic(err)
    }

    // add a job to the scheduler
    _, err = s.NewJob(
        gocron.DurationJob(
            10*time.Second,
        ),
        gocron.NewTask(
            func(a string, b int) {
                fmt.Println(time.Now().Format("2006-01-02 15:04:05"), a)
            },
            "hello",
            1,
        ),
    )
    if err != nil {
        panic(err)
    }

    s.Start()

    // run schedule for 20 seconds
    select {
    case <-time.After(20 * time.Second):
    }

    // restart the scheduler
    s.StopJobs()
    s.Start()
    fmt.Println("Restarted Scheduler")

    // run schedule for another 30 seconds
    select {
    case <-time.After(30 * time.Second):
    }

    err = s.Shutdown()
    if err != nil {
        panic(err)
    }
}

Output:

2024-04-29 09:08:59 hello
Restarted Scheduler

Expected output:

2024-04-29 09:10:21 hello
Restarted Scheduler
2024-04-29 09:10:31 hello
2024-04-29 09:10:41 hello
2024-04-29 09:10:51 hello

Version

v2.5.0

Expected behavior

Scheduled jobs should resume after Scheduler.Start()

@jmutschler jmutschler added the bug Something isn't working label Apr 29, 2024
@JohnRoesler
Copy link
Contributor

@jmutschler yes this is definitely a bug. Sorry, I haven't had a chance to dig into the code yet and see what's getting hung up.

@jmutschler
Copy link
Author

No problem. I appreciate your time on this!

@JohnRoesler
Copy link
Contributor

Found the issue, easy one to fix. Should be out here pretty soon

@jmutschler
Copy link
Author

Thank you @JohnRoesler!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants