Reputation: 48453
I have an EC2 instance that is in the Oregon region. When I log in on the server, I see the following:
System information as of Wed Apr 13 04:13:49 UTC 2016
Current time in NYC: 12:51 PM.
All my rake tasks are set according on the NYC time. I had scheduled a task that will run every morning on 4AM, but after moving to AWS EC2, this tasks is running on midnight.
I tried to set the time zone in the config/environments/production.rb
:
config.time_zone = 'Eastern Time (US & Canada)'
config.active_record.default_timezone = 'Eastern Time (US & Canada)'
But even after restarting the server the tasks are being launched every midnight, not 4AM.
What should be my next steps here?
Thank you.
Upvotes: 3
Views: 392
Reputation: 1118
A subsequent comment on this issue indicates that the whenever
gem is used. The whenever
policy is to avoid timezone logic, leaving it up to you. There is, however, this approach to whenever.rb
:
Time.zone = "US/Eastern"
every 1.day, :at => Time.zone.parse('4:30 am').utc do
command 'echo hello'
end
This allows your server to continue to live on UTC time (which your post indicates it does) while your code has its own conception of how to describe specific moments on the clock. The author indicates he favors this approach, and you can verify it yourself by inspecting the crontab (crontab -l
) after a deployment. It's important to note that your crontab will be in UTC; this system library has no special knowledge of your Rails environment or runtime.
Upvotes: 1