jasonlvhit / gocron

A Golang Job Scheduling Package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schedule task every X hours from a date in the past

antoniocapizzi95 opened this issue · comments

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.

@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! go-co-op/gocron#106

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