diff --git a/lib/sidetiq/lock/meta_data.rb b/lib/sidetiq/lock/meta_data.rb index a22042f..aa72d37 100644 --- a/lib/sidetiq/lock/meta_data.rb +++ b/lib/sidetiq/lock/meta_data.rb @@ -13,12 +13,12 @@ module Sidetiq end def from_json(json = "") - # Avoid TypeError when nil is passed to JSON.parse. + # Avoid TypeError when nil is passed to Sidekiq.load_json. json = "" if json.nil? - hash = JSON.parse(json, symbolize_names: true) + hash = Sidekiq.load_json(json).symbolize_keys new(hash) - rescue JSON::ParserError => e + rescue StandardError => e if json != "" # Looks like garbage lock metadata, so report it. handle_exception(e, context: "Garbage lock meta data detected: #{json}") diff --git a/lib/sidetiq/middleware/history.rb b/lib/sidetiq/middleware/history.rb index 4e3bcaa..0119a09 100644 --- a/lib/sidetiq/middleware/history.rb +++ b/lib/sidetiq/middleware/history.rb @@ -41,7 +41,7 @@ module Sidetiq Sidekiq.redis do |redis| list_name = "sidetiq:#{worker.class.name}:history" - redis.lpush(list_name, JSON.dump(entry)) + redis.lpush(list_name, Sidekiq.dump_json(entry)) redis.ltrim(list_name, 0, Sidetiq.config.worker_history - 1) end end diff --git a/lib/sidetiq/views/history.erb b/lib/sidetiq/views/history.erb index 03e331e..551664c 100644 --- a/lib/sidetiq/views/history.erb +++ b/lib/sidetiq/views/history.erb @@ -19,7 +19,7 @@ <% @history.each do |entry| %> - <% entry = JSON.parse(entry, symbolize_names: true) %> + <% entry = Sidekiq.load_json(entry).symbolize_keys %> <%= entry[:status].capitalize %> <%= Time.parse(entry[:timestamp]).strftime("%m/%d/%Y %I:%M:%S%p") %> diff --git a/sidetiq.gemspec b/sidetiq.gemspec index df8d497..cdfaac2 100644 --- a/sidetiq.gemspec +++ b/sidetiq.gemspec @@ -22,7 +22,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'sidekiq', '~> 2.14.0' gem.add_dependency 'celluloid', '>= 0.14.1' gem.add_dependency 'ice_cube', '~> 0.11.0' - gem.add_dependency 'json' gem.add_development_dependency 'rake' gem.add_development_dependency 'sinatra' diff --git a/test/test_history.rb b/test/test_history.rb index 43bcaef..e17b8e7 100644 --- a/test/test_history.rb +++ b/test/test_history.rb @@ -13,7 +13,7 @@ class TestHistory < Sidetiq::TestCase redis.lrange('sidetiq:TestHistory::HistoryWorker:history', 0, -1) end - actual = JSON.parse(entry[0], symbolize_names: true) + actual = Sidekiq.load_json(entry[0]).symbolize_keys assert_equal 'success', actual[:status] @@ -37,7 +37,7 @@ class TestHistory < Sidetiq::TestCase redis.lrange('sidetiq:TestHistory::HistoryWorker:history', 0, -1) end - actual = JSON.parse(entry[0], symbolize_names: true) + actual = Sidekiq.load_json(entry[0]).symbolize_keys assert_equal 'failure', actual[:status] diff --git a/test/test_lock_meta_data.rb b/test/test_lock_meta_data.rb index 478a513..7ca7ea7 100644 --- a/test/test_lock_meta_data.rb +++ b/test/test_lock_meta_data.rb @@ -78,7 +78,7 @@ class TestLockMetaData < Sidetiq::TestCase hash = { timestamp: 42, owner: "me", key: "foobar" } md = Sidetiq::Lock::MetaData.new(hash) - assert_equal hash, JSON.parse(md.to_json, symbolize_names: true) + assert_equal hash, Sidekiq.load_json(md.to_json).symbolize_keys end def test_to_s