Use UTC instead of system timezone #2

Merged
merged 1 commit into from Nov 18, 2011
@@ -26,7 +26,7 @@ class QueueAudit < ActiveRecord::Base
}
named_scope :failed, lambda {
- { :conditions => [ 'completed_at is null AND timeout_at < ?', Time.now ], :order => 'timeout_at asc' }
+ { :conditions => [ 'completed_at is null AND timeout_at < ?', Time.now.utc ], :order => 'timeout_at asc' }
}
named_scope :complete, lambda {
@@ -80,22 +80,22 @@ def duration
end
def heartbeat!
- update_attribute(:timeout_at, Time.now + duration)
+ update_attribute(:timeout_at, Time.now.utc + duration)
end
def fail!
- update_attribute(:timeout_at, Time.now)
+ update_attribute(:timeout_at, Time.now.utc)
end
def enqueued!
- self.enqueued_at = Time.now
+ self.enqueued_at = Time.now.utc
self.timeout_at = enqueued_at + duration
self.enqueue_count += 1
save!
end
def complete!
- self.completed_at = Time.now
+ self.completed_at = Time.now.utc
save!
end
@@ -104,7 +104,7 @@ def complete?
end
def retryable?
- Time.now > (timeout_at + delay)
+ Time.now.utc > (timeout_at + delay)
end
# 1, 8, 27, 64, 125, 216, etc. minutes.
View
@@ -65,16 +65,17 @@ class QueueAuditTest < MiniTest::Unit::TestCase
describe 'failed' do
before do
@audit.enqueued!
+ @audit.reload
end
it 'provides audits enqueued for more than than the expected run duration' do
- Timecop.freeze(@audit.duration.from_now + 1.second) do
+ Timecop.freeze(@audit.timeout_at + 1.second) do
assert_equal [ @audit ], QueueAudit.failed
end
end
it 'does not provides audits enqueued less than the expected run duration' do
- Timecop.freeze(@audit.duration.from_now - 1.second) do
+ Timecop.freeze(@audit.timeout_at - 1.second) do
assert_equal [], QueueAudit.failed
end
end
View
@@ -10,6 +10,9 @@
database_config = YAML.load_file(File.join(File.dirname(__FILE__), 'database.yml'))
ActiveRecord::Base.establish_connection(database_config['test'])
+ActiveRecord::Base.default_timezone = :utc
+Time.zone = Time.__send__(:get_zone, 'UTC')
+Time.zone_default = Time.__send__(:get_zone, 'UTC')
require 'schema'
module Resque
@@ -54,4 +57,3 @@ def work_queue(name)
worker.process
end
-