I've been doing some test with cron jobs with timezones. My goal is to setup 1 cron job per timezone so it can be run independently of the server location.
package main
import (
"fmt"
"github.com/robfig/cron"
"os"
"os/signal"
"time"
)
func helloWorld() {
fmt.Println("hello world")
}
func main() {
s, err1 := cron.Parse("26 15 * * *")
fmt.Println(err1)
l, err := time.LoadLocation("Asia/Tokyo")
fmt.Println(err)
c := cron.NewWithLocation(l)
c.Schedule(s, cron.FuncJob(helloWorld))
c.Start()
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt, os.Kill)
<-sig
}
Here i'm just trying to make a test. I expect to see helloWorld at 15:26 Tokyo time. ( 3:26PM )
The sig snippet is something i've found on stack overflow for testing purposes so that the program doesn't close before the cron job has time to run.
I'm always setting up the time 1 or 2 minutes ahead and it's never working. any idea why ?