jasonlvhit / gocron

A Golang Job Scheduling Package.
BSD 2-Clause "Simplified" License
3.45k stars 346 forks source link

Schedule task every X hours from a date in the past #166

Closed antoniocapizzi95 closed 3 years ago

antoniocapizzi95 commented 3 years ago

Hello, I'm using this method to schedule a task:

// Begin job at a specific date/time
t := time.Date(2019, time.November, 10, 15, 0, 0, 0, time.Local)
gocron.Every(1).Hour().From(&t).Do(task)

My aim is to schedule a task every 3 hours from midnight, but it seems that at startup it starts counting from the script execution time. My code is the below:

today := time.Now()
t := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, time.Local)
gocron.Every(3).Hours().From(&t).Do(task)

For example if I run this code at 2:00 AM, I'd like that task starts at 3:00 AM, not at 5:00 AM. Is there a method to do this? Thanks.

JohnRoesler commented 3 years ago

@antoniocapizzi95 hey, this repo is no longer maintained (per the note in the readme) - we have a maintained fork over at https://github.com/go-co-op/gocron and recently added support for this exact use! https://github.com/go-co-op/gocron/issues/106

antoniocapizzi95 commented 3 years ago

@JohnRoesler thank you very much, I will try this fork.