mirror of
https://github.com/endofunky/sidetiq.git
synced 2022-11-09 13:53:30 -05:00
Use Sidekiq's wrappers for parsing/generating JSON.
This commit is contained in:
parent
9354bc4e08
commit
e7bed3a4f4
6 changed files with 8 additions and 9 deletions
|
@ -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}")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</thead>
|
||||
|
||||
<% @history.each do |entry| %>
|
||||
<% entry = JSON.parse(entry, symbolize_names: true) %>
|
||||
<% entry = Sidekiq.load_json(entry).symbolize_keys %>
|
||||
<tr class="<%= 'error' if entry[:status] == 'failure' %>">
|
||||
<td><%= entry[:status].capitalize %></td>
|
||||
<td><%= Time.parse(entry[:timestamp]).strftime("%m/%d/%Y %I:%M:%S%p") %></td>
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue