From 85e03a7f68fc12114d8c24d6dd40b045832c908f Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 9 Mar 2020 17:37:49 +0100 Subject: [PATCH] DEV: Replace `Time.new` with `Time.now` (#9142) (or `Time.zone.now`) --- app/jobs/regular/run_heartbeat.rb | 2 +- app/models/post.rb | 2 +- config/unicorn.conf.rb | 8 ++++---- lib/distributed_memoizer.rb | 4 ++-- spec/jobs/heartbeat_spec.rb | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/jobs/regular/run_heartbeat.rb b/app/jobs/regular/run_heartbeat.rb index 4d5c0130531..4a0691171ad 100644 --- a/app/jobs/regular/run_heartbeat.rb +++ b/app/jobs/regular/run_heartbeat.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 7e56dfa66bc..751d8b721f1 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rb index 6c0ac9a7ef3..dd698f379f7 100644 --- a/config/unicorn.conf.rb +++ b/config/unicorn.conf.rb @@ -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 diff --git a/lib/distributed_memoizer.rb b/lib/distributed_memoizer.rb index 44a52806b4e..559833f2b6d 100644 --- a/lib/distributed_memoizer.rb +++ b/lib/distributed_memoizer.rb @@ -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 diff --git a/spec/jobs/heartbeat_spec.rb b/spec/jobs/heartbeat_spec.rb index fb39ffd36bd..f86c88ef321 100644 --- a/spec/jobs/heartbeat_spec.rb +++ b/spec/jobs/heartbeat_spec.rb @@ -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