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

not working #390

Closed
zoujunrong opened this issue May 2, 2021 · 8 comments
Closed

not working #390

zoujunrong opened this issue May 2, 2021 · 8 comments

Comments

@zoujunrong
Copy link

zoujunrong commented May 2, 2021

// "github.com/robfig/cron/v3"

func main() {
  c := cron.New()
  c.AddFunc("* * * * * *", func() {
    fmt.Println("working")
  })
  c.Start()
  
  select {}
}

use the latest version v3.0.1 and 3.0.0 is also not working, my useage was wrong?

@AdmiralDollBug
Copy link

It also happens on me. All of the jobs configured in format of cron expression does not work.
cron version: v3.0.1
go version: 1.15.2

@fujiawei-dev
Copy link

Me too...

@Alanthur
Copy link

The example was wrong. You should take 5 fields for AddFunc funtion.
correct:
c.AddFunc("30 3 * * *", func() { fmt.Println("working") })
wrong:
c.AddFunc("0 30 * * * *", func() { fmt.Println("working") })

@AdmiralDollBug
Copy link

AdmiralDollBug commented May 24, 2021

I read the code again, and found that the cron.New function without parameter creates a "standardParser", which does not support the "Second" field

var standardParser = NewParser(
	Minute | Hour | Dom | Month | Dow | Descriptor,
)

...

func New(opts ...Option) *Cron {
	c := &Cron{
		entries:   nil,
		chain:     NewChain(),
		add:       make(chan *Entry),
		stop:      make(chan struct{}),
		snapshot:  make(chan chan []Entry),
		remove:    make(chan EntryID),
		running:   false,
		runningMu: sync.Mutex{},
		logger:    DefaultLogger,
		location:  time.Local,
		parser:    standardParser,
	}
	for _, opt := range opts {
		opt(c)
	}
	return c
}

To support "Second" field, create the cron object like this:

cron.New(cron.WithSeconds())

BTW,the doc on go.pkg.dev needs to be updated because it's misleading now...

@zoujunrong
Copy link
Author

The example was wrong. You should take 5 fields for AddFunc funtion.
correct:
c.AddFunc("30 3 * * *", func() { fmt.Println("working") })
wrong:
c.AddFunc("0 30 * * * *", func() { fmt.Println("working") })

c.AddFunc("* * * * * *", func() { fmt.Println("working") })
also not working.

@danielMensah
Copy link

Has this issue been solve? having issues just running c.AddFunc("* * * * *", func() { fmt.Println("working") })

@grosenberry
Copy link

Has this issue been solve? having issues just running c.AddFunc("* * * * *", func() { fmt.Println("working") })

I was not able to get this line to work successfully, the only way I've found to get this to work is to use the above suggestion cron.New(cron.WithSeconds()) with the 6 field notation and it began working perfectly.

Hopefully this helps anyone landing on the page. I'm on v3.0.1.

@zoujunrong
Copy link
Author

zoujunrong commented Oct 10, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants