Skip to content

How to initialize a task without first run? #176

Answered by JohnRoesler
hwebb asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @hwebb you can set the individual job or the entire scheduler to wait for the first interval before running rather than running immediately.

s.Every(60).Minutes().WaitForSchedule().Do(task)

or

s.WaitForScheduleAll()
s.Every(60).Minutes().Do(task)

The SinglettonMode() is relevant when you have long running tasks that may run longer than the scheduled interval.

References:
https://pkg.go.dev/github.com/go-co-op/gocron#Scheduler.WaitForSchedule
https://pkg.go.dev/github.com/go-co-op/gocron#Scheduler.WaitForScheduleAll
https://pkg.go.dev/github.com/go-co-op/gocron#Scheduler.SingletonMode

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hwebb
Comment options

@JohnRoesler
Comment options

Answer selected by JohnRoesler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants