plashchynski / crono

A time-based background job scheduler daemon (just like Cron) for Rails
https://github.com/plashchynski/crono
Apache License 2.0
687 stars 56 forks source link

Timezone issues #62

Open MohamedBassem opened 7 years ago

MohamedBassem commented 7 years ago

Hi,

I have a crontab that contains:

Crono.perform(SendPreLockdownEmailsJob).every 1.days, at: '00:01'

Rails' timezone is set to UTC+4. According to that, the job should always run at 20:00 UTC everyday. The problem is that it sometimes run on 00:01 UTC too for some reason that I don't understand. You can see what I mean from the job's logs:

I, [2017-05-07T20:01:00.000688 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-07T20:01:00.333131 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.33 seconds
I, [2017-05-08T00:01:00.001753 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-08T00:01:00.245461 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.24 seconds
I, [2017-05-08T20:50:36.271039 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-08T20:50:36.365803 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.09 seconds
I, [2017-05-09T00:01:00.000563 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-09T00:01:00.128860 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.13 seconds
I, [2017-05-09T20:01:00.000598 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-09T20:01:00.181408 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.18 seconds
I, [2017-05-10T20:01:00.001467 #9]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-10T20:01:00.304802 #9]  INFO -- : Finished SendPreLockdownEmailsJob in 0.30 seconds
I, [2017-05-11T00:01:00.000725 #9]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-11T00:01:00.238791 #9]  INFO -- : Finished SendPreLockdownEmailsJob in 0.24 seconds
I, [2017-05-12T00:01:00.000630 #9]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-12T00:01:00.233772 #9]  INFO -- : Finished SendPreLockdownEmailsJob in 0.23 seconds
I, [2017-05-12T20:01:00.000284 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-12T20:01:00.329280 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.33 seconds
I, [2017-05-13T00:01:00.000260 #8]  INFO -- : Perform SendPreLockdownEmailsJob
I, [2017-05-13T00:01:00.338922 #8]  INFO -- : Finished SendPreLockdownEmailsJob in 0.34 seconds

So the problem is that the at option is sometimes interpreted as UTC, sometimes interpreted as Rails timezone and sometimes both. Any help?

trustarun commented 7 years ago

Same issue for me. In my case, It do not pick the timezone configuration but pick my system time.

System time 2.2.2 :023 > Time.now => 2017-11-08 19:04:54 +0530 Scheduling few minute later of above time work Crono.perform(DataCsvReport).every 1.day, at: {hour: 19 min: 10}

Time configured in application 2.2.2 :024 > Time.zone.now => Wed, 08 Nov 2017 08:35:14 EST -05:00 Scheduling few minute later of above configured time do not work Crono.perform(DataCsvReport).every 1.day, at: {hour: 08 min: 40}

efreesen commented 5 years ago

We solved it this way:

offset = Time.now.zone

Crono.perform(Worker).every 1.day, at: "00:00 #{offset}"