1
0
Fork 0
mirror of https://github.com/endofunky/sidetiq.git synced 2022-11-09 13:53:30 -05:00

Add option to use UTC instead of local time.

This commit is contained in:
Tobias Svensson 2013-02-01 18:27:27 +00:00
parent 45bf3a24ba
commit 932b6a01c0
7 changed files with 26 additions and 6 deletions

View file

@ -95,6 +95,9 @@ Sidetiq.configure do |config|
# Clock locking key expiration in ms (default: 1000). # Clock locking key expiration in ms (default: 1000).
config.lock_expire = 100 config.lock_expire = 100
# When `true` uses UTC instead of local times (default: false)
config.utc = false
end end
``` ```

View file

@ -92,6 +92,6 @@ void Init_sidetiq_ext()
msidetiq = rb_define_module("Sidetiq"); msidetiq = rb_define_module("Sidetiq");
esidetiq_error = rb_define_class_under(msidetiq, "Error", rb_eStandardError); esidetiq_error = rb_define_class_under(msidetiq, "Error", rb_eStandardError);
csidetiq_clock = rb_define_class_under(msidetiq, "Clock", rb_cObject); csidetiq_clock = rb_define_class_under(msidetiq, "Clock", rb_cObject);
rb_define_method(csidetiq_clock, "gettime", sidetiq_gettime, 0); rb_define_private_method(csidetiq_clock, "clock_gettime", sidetiq_gettime, 0);
} }

View file

@ -3,13 +3,14 @@ module Sidetiq
config.priority = Thread.main.priority config.priority = Thread.main.priority
config.resolution = 1 config.resolution = 1
config.lock_expire = 1000 config.lock_expire = 1000
config.utc = false
end end
class Clock class Clock
include Singleton include Singleton
include MonitorMixin include MonitorMixin
START_TIME = Time.local(2010, 1, 1) START_TIME = Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1)
attr_reader :schedules attr_reader :schedules
@ -34,6 +35,10 @@ module Sidetiq
end end
end end
def gettime
Sidetiq.config.utc ? clock_gettime.utc : clock_gettime
end
private private
def enqueue(worker, time) def enqueue(worker, time)

View file

@ -15,7 +15,7 @@ header.row
= worker.name = worker.name
td= worker.get_sidekiq_options['queue'] td= worker.get_sidekiq_options['queue']
td td
== relative_time(schedule.next_occurrence) == relative_time(schedule.next_occurrence(@time))
td td
a href="#{root_path}sidetiq/#{worker.name}" Details a href="#{root_path}sidetiq/#{worker.name}" Details
- else - else

View file

@ -30,7 +30,7 @@ table class="table table-striped table-bordered table-white" style="width: 100%;
thead thead
th style="width: 25%" Next 10 runs th style="width: 25%" Next 10 runs
th style="width: 75%" th style="width: 75%"
- @schedule.next_occurrences(10).each do |time| - @schedule.next_occurrences(10, @time).each do |time|
tr tr
td td
time= time.getutc time= time.getutc

View file

@ -13,14 +13,19 @@ module Sidetiq
end end
app.get "/sidetiq" do app.get "/sidetiq" do
@schedules = Sidetiq::Clock.instance.schedules clock = Sidetiq::Clock.instance
@schedules = clock.schedules
@time = clock.gettime
slim :sidetiq slim :sidetiq
end end
app.get "/sidetiq/:name" do app.get "/sidetiq/:name" do
halt 404 unless (name = params[:name]) halt 404 unless (name = params[:name])
schedules = Sidetiq::Clock.instance.schedules clock = Sidetiq::Clock.instance
schedules = clock.schedules
@time = clock.gettime
@worker, @schedule = schedules.select do |worker, schedule| @worker, @schedule = schedules.select do |worker, schedule|
worker.name == name worker.name == name

View file

@ -13,6 +13,13 @@ class TestClock < Sidetiq::TestCase
refute_nil clock.gettime.tv_nsec refute_nil clock.gettime.tv_nsec
end end
def test_gettime_utc
refute clock.gettime.utc?
Sidetiq.config.utc = true
assert clock.gettime.utc?
Sidetiq.config.utc = false
end
class FakeWorker; end class FakeWorker; end
def test_enqueues_jobs_by_schedule def test_enqueues_jobs_by_schedule