DEV: Replace `Time.new` with `Time.now` (#9142)

(or `Time.zone.now`)
This commit is contained in:
Jarek Radosz 2020-03-09 17:37:49 +01:00 committed by GitHub
parent fff0e0980d
commit 85e03a7f68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -10,7 +10,7 @@ module Jobs
end
def execute(args)
Discourse.redis.set(self.class.heartbeat_key, Time.new.to_i.to_s)
Discourse.redis.set(self.class.heartbeat_key, Time.now.to_i.to_s)
end
def self.last_heartbeat

View File

@ -714,7 +714,7 @@ class Post < ActiveRecord::Base
self.cooked = cook(raw, topic_id: topic_id)
end
self.baked_at = Time.new
self.baked_at = Time.zone.now
self.baked_version = BAKED_VERSION
end

View File

@ -130,9 +130,9 @@ before_fork do |server, worker|
def check_sidekiq_heartbeat
@sidekiq_heartbeat_interval ||= 30.minutes
@sidekiq_next_heartbeat_check ||= Time.new.to_i + @sidekiq_heartbeat_interval
@sidekiq_next_heartbeat_check ||= Time.now.to_i + @sidekiq_heartbeat_interval
if @sidekiq_next_heartbeat_check < Time.new.to_i
if @sidekiq_next_heartbeat_check < Time.now.to_i
last_heartbeat = Jobs::RunHeartbeat.last_heartbeat
restart = false
@ -142,13 +142,13 @@ before_fork do |server, worker|
restart = true
end
if last_heartbeat < Time.new.to_i - @sidekiq_heartbeat_interval
if last_heartbeat < Time.now.to_i - @sidekiq_heartbeat_interval
STDERR.puts "Sidekiq heartbeat test failed, restarting"
Rails.logger.warn "Sidekiq heartbeat test failed, restarting"
restart = true
end
@sidekiq_next_heartbeat_check = Time.new.to_i + @sidekiq_heartbeat_interval
@sidekiq_next_heartbeat_check = Time.now.to_i + @sidekiq_heartbeat_interval
if restart
Demon::Sidekiq.restart

View File

@ -15,11 +15,11 @@ class DistributedMemoizer
unless result = redis.get(redis_key)
redis_lock_key = self.redis_lock_key(key)
start = Time.new
start = Time.now
got_lock = false
begin
while Time.new < start + MAX_WAIT && !got_lock
while Time.now < start + MAX_WAIT && !got_lock
LOCK.synchronize do
got_lock = get_lock(redis, redis_lock_key)
end

View File

@ -14,7 +14,7 @@ describe ::Jobs::Heartbeat do
Sidekiq::Testing.inline! do
::Jobs::Heartbeat.new.perform(nil)
expect(::Jobs::RunHeartbeat.last_heartbeat).to eq(Time.new.to_i)
expect(::Jobs::RunHeartbeat.last_heartbeat).to eq(Time.now.to_i)
end
end
end