0

I'm making the cron job for monitoring the data. But before this while I'm reading the documentation of the cron in GoDoc in this they say we will run the cron according to the particular time_zone and intervals. Now I'm using only intervals in the cron job. But, Now I want to use time_zone too in the cron job means to say cron job will run according to the particular time_zone on the particular time interval. Suppose I'm in USA and there are different time_zone and I'm in Chicago and I want my cron will run every after 2 hours according to the time_zone of each country. Can we use time_zone and interval together? if Yes, Then please tell how can we use it in below function:-

cron.go

package cron

import (
    "gopkg.in/robfig/cron.v2"
)
func RunCron() {
    c := cron.New()

    c.AddFunc("Here I want the time_zone and intervals together", AutomaticChargedCron)
    c.Start()
}

I No, Can you tell me that how this will posible to make a cron like that or make a other cron for monitoring the time_zone.

misha
  • 139
  • 1
  • 3
  • 14
  • To be fair I have created a cron which runs every 2AM in night according to US timings. But If you are creating a cron which runs every 2 hours, I do'nt think you need to add a timezone. Since the cron is not running once or twice in a day. It is running every 2 hours. – Himanshu Oct 05 '18 at 04:33
  • @Himanshu not every 2 hours. okay, I'm explain you one thing is that suppose the time in `chicago is 05:00` AM and in new york is `06:00AM`. and there is a booking for chicago start at `06:00 AM` and end at `07:00 AM` and There is a booking for New york start at `06:30 AM` and end at `07:30 AM` and the admin set the cron time of 2 hours then for chicago it will run at `09:00 AM` and for New York it will run `09:30 AM` Now you got what I want? – misha Oct 05 '18 at 04:45
  • @Himanshu, two hours on a wall clock aren't always 120 minutes on a stopwatch: https://play.golang.org/p/q4eBklpjUnn. Selecting the correct timezone for the desired behavior is important. – Peter Oct 05 '18 at 07:23
  • @misha, what's unclear about the example in the [usage](https://godoc.org/gopkg.in/robfig/cron.v2#hdr-Usage)? – Peter Oct 05 '18 at 07:31
  • Hey Misha, I think you want to do some delayed processing of some kind, I would suggest you take a look at Publish-Subscribe model, as cron based processes do add a bit of complexity and doesn't scale too well. For the cron although, you can try using tickers, example https://stackoverflow.com/questions/19549199/golang-implementing-a-cron-executing-tasks-at-a-specific-time , golang also provides native tickers, so you can implement your own version and run multiple tickers for different UTC offsets. Here: https://gobyexample.com/tickers – ishaan Oct 05 '18 at 09:40

0 Answers0