From 48ca4d52377828d9c052e0166a09242db8350692 Mon Sep 17 00:00:00 2001 From: Jeremiah Church Date: Thu, 9 Mar 2023 14:14:41 -0500 Subject: [PATCH 1/2] fix lock & changelog times for nil.to_f --- lib/sidekiq_unique_jobs/lock.rb | 5 ++++- lib/sidekiq_unique_jobs/web/helpers.rb | 2 ++ lib/sidekiq_unique_jobs/web/views/changelogs.erb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq_unique_jobs/lock.rb b/lib/sidekiq_unique_jobs/lock.rb index e6cb8985..9ddb571f 100644 --- a/lib/sidekiq_unique_jobs/lock.rb +++ b/lib/sidekiq_unique_jobs/lock.rb @@ -47,7 +47,10 @@ def self.create(digest, job_id, lock_info = {}) # def initialize(key, time: nil) @key = get_key(key) - @created_at = time.is_a?(Float) ? time : time.to_f + time = time.is_a?(Float) ? time : time.to_f + if time.nonzero? + @created_at = time + end end # diff --git a/lib/sidekiq_unique_jobs/web/helpers.rb b/lib/sidekiq_unique_jobs/web/helpers.rb index fde31aa3..0cb27403 100644 --- a/lib/sidekiq_unique_jobs/web/helpers.rb +++ b/lib/sidekiq_unique_jobs/web/helpers.rb @@ -146,6 +146,8 @@ def relative_time(time) # @return [String] a html safe string with relative time information # def safe_relative_time(time) + return unless time + time = parse_time(time) relative_time(time) diff --git a/lib/sidekiq_unique_jobs/web/views/changelogs.erb b/lib/sidekiq_unique_jobs/web/views/changelogs.erb index 64794b8f..fe0e7009 100644 --- a/lib/sidekiq_unique_jobs/web/views/changelogs.erb +++ b/lib/sidekiq_unique_jobs/web/views/changelogs.erb @@ -42,7 +42,7 @@ <% @changelogs.each do |changelog| %> - <%= "bogus" %> + <%= safe_relative_time(changelog['time']) || "bogus" %> <%= changelog["digest"] %> <%= changelog["script"] %> <%= changelog["job_id"] %> From 1f2937321a92bedce22644711a76f6053e72051b Mon Sep 17 00:00:00 2001 From: Jeremiah Church Date: Mon, 13 Mar 2023 14:27:08 -0400 Subject: [PATCH 2/2] rubocop -a --- lib/sidekiq_unique_jobs/lock.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sidekiq_unique_jobs/lock.rb b/lib/sidekiq_unique_jobs/lock.rb index 9ddb571f..3be0a65e 100644 --- a/lib/sidekiq_unique_jobs/lock.rb +++ b/lib/sidekiq_unique_jobs/lock.rb @@ -46,11 +46,11 @@ def self.create(digest, job_id, lock_info = {}) # @param [Timstamp, Float] time nil optional timestamp to initiate this lock with # def initialize(key, time: nil) - @key = get_key(key) + @key = get_key(key) time = time.is_a?(Float) ? time : time.to_f - if time.nonzero? - @created_at = time - end + return unless time.nonzero? + + @created_at = time end #