Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Last active November 30, 2016 18:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save toolmantim/76c0c35d57c15a292ba8 to your computer and use it in GitHub Desktop.
Save toolmantim/76c0c35d57c15a292ba8 to your computer and use it in GitHub Desktop.
An addition to Sidetiq to make it easier to declare the worker's schedule's timezone. Assumes ActiveRecord::TimeZone is available.
# 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
@nikhilvij
Copy link

Used this but it still seems to be scheduling according to the utc time for me

@nikhilvij
Copy link

Apparently the update to newer version of ice_cube which allowed us to do this was reverted due to memory leak issue. A note for someone else like me who comes looking here.

@devhero
Copy link

devhero commented Oct 6, 2015

@nikhilvij
the version of ice_cube in your fork of sidetiq is 0.12.1, but the latest is 0.13.1.

Which version causes the memory leack?
Is it safe the 0.12.1?

@brunomperes
Copy link

brunomperes commented Nov 30, 2016

Where would this file go on the rails app? Does it work with sidetiq 0.7.2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment