go-co-op / gocron

Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron
MIT License
5.7k stars 308 forks source link

[BUG] - update job(with gocron.Job param) fail #578

Closed tricknife closed 9 months ago

tricknife commented 1 year ago

Describe the bug

When I tried to update a job(copy from the example), it returns an error: gocron: wrong list of params.

To Reproduce

func update() error{
    task := func(in string, job gocron.Job) {
        fmt.Printf("this job's last run: %s this job's next run: %s\n", job.LastRun(), job.NextRun())
        fmt.Printf("in argument is %s\n", in)

        ticker := time.NewTicker(100 * time.Millisecond)
        defer ticker.Stop()

        for {
            select {
            case <-job.Context().Done():
                fmt.Printf("function has been canceled, performing cleanup and exiting gracefully\n")
                return
            case <-ticker.C:
                fmt.Printf("performing a hard job that takes a long time that I want to kill whenever I want\n")
            }
        }
    }

    var err error
    s := gocron.NewScheduler(time.UTC)
    s.SingletonModeAll()
    s.WaitForScheduleAll()
    j, err := s.Every(1).Hour().Tag("myJob").DoWithJobDetails(task, "foo")
    if err != nil {
        log.Fatalln("error scheduling job", err)
        return err
    }

    s.StartAsync()

    time.Sleep(time.Second)
    _, err = s.Job(j).Every(3).Hour().Update()
    if err != nil {
        log.Fatalln("error Update job", err)
        return err
    }
    log.Printf("update over")
    return nil
}

Version

v1.34.2

Expected behavior

nothing happend

Additional context

JohnRoesler commented 9 months ago

This is solved in v2