Forked from toolmantim/sidetiq_schedule_time_zone_additions.rb
Last active
August 29, 2015 14:07
-
-
Save kivanio/74f4b90567d35ba133de to your computer and use it in GitHub Desktop.
This file contains 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
# Timezone extension to Sidetiq | |
Sidetiq::Schedulable::ClassMethods.class_eval do | |
# Sets the time zone for the recurrence rules. | |
# | |
# Example: | |
# | |
# class MyWorker | |
# include Sidekiq::Worker | |
# include Sidetiq::Schedulable | |
# | |
# schedule_time_zone "Australia/Perth" | |
# | |
# recurrence do | |
# daily.hour_of_day(13) | |
# end | |
# | |
# def perform | |
# puts "It's 1pm in Perth" | |
# end | |
# end | |
def schedule_time_zone(time_zone_name) | |
zone = ActiveSupport::TimeZone[time_zone_name] | |
# We use 2010-1-1 for the start time because that's what Sidetiq uses, and | |
# you probably need it to be in the past to do backfilling | |
schedule.start_time = zone.local(2010, 1, 1) | |
end | |
end | |
Sidetiq::Schedule.class_eval do | |
# Returns the time_zone for the schedule. Handy in Rspec assertions to | |
# verify that a worker's schedule is using the right timezone. | |
def time_zone | |
start_time.time_zone | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment