Last active
December 25, 2015 03:29
-
-
Save griffithac/6910223 to your computer and use it in GitHub Desktop.
Fix issue with timezones and the whenever gem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# schedule.rb | |
set :output, "/path/to/log/cron.log" | |
# Requires that your production server is set to UTC time | |
# Subclass Time and override self.parse to adjust for timezone offset | |
class TimeInZone < Time | |
def initialize | |
super | |
end | |
def self.parse args, utc_offset = 0 | |
hours = 3600 # seconds in hour | |
super(args) - (hours * utc_offset) | |
end | |
end | |
LOCAL_TIME_ZONE_OFFSET = -7 # Set default offset | |
# Add helper method to DRY up the cron tasks | |
def local time, utc_offset = LOCAL_TIME_ZONE_OFFSET | |
TimeInZone.parse(time, utc_offset) | |
end | |
# Cron tasks here | |
every 1.day, at: local('5:00 am') do | |
rake "example:task" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment