mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Dump error backtraces as json before compressing (#4323)
This commit is contained in:
parent
9e99645074
commit
ce7d1661c4
3 changed files with 25 additions and 4 deletions
|
@ -438,12 +438,18 @@ module Sidekiq
|
|||
|
||||
def uncompress_backtrace(backtrace)
|
||||
if backtrace.is_a?(Array)
|
||||
# Handle old jobs with previous backtrace format
|
||||
# Handle old jobs with raw Array backtrace format
|
||||
backtrace
|
||||
else
|
||||
decoded = Base64.decode64(backtrace)
|
||||
uncompressed = Zlib::Inflate.inflate(decoded)
|
||||
Marshal.load(uncompressed)
|
||||
begin
|
||||
Sidekiq.load_json(uncompressed)
|
||||
rescue
|
||||
# Handle old jobs with marshalled backtrace format
|
||||
# TODO Remove in 7.x
|
||||
Marshal.load(uncompressed)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -254,7 +254,7 @@ module Sidekiq
|
|||
end
|
||||
|
||||
def compress_backtrace(backtrace)
|
||||
serialized = Marshal.dump(backtrace)
|
||||
serialized = Sidekiq.dump_json(backtrace)
|
||||
compressed = Zlib::Deflate.deflate(serialized)
|
||||
Base64.encode64(compressed)
|
||||
end
|
||||
|
|
|
@ -259,12 +259,27 @@ describe 'API' do
|
|||
assert_equal [1,2,3], x.display_args
|
||||
end
|
||||
|
||||
it 'handles old jobs error_backtrace format' do
|
||||
it 'handles previous (raw Array) error_backtrace format' do
|
||||
add_retry
|
||||
job = Sidekiq::RetrySet.new.first
|
||||
assert_equal ['line1', 'line2'], job.error_backtrace
|
||||
end
|
||||
|
||||
it 'handles previous (marshalled Array) error_backtrace format' do
|
||||
backtrace = ['line1', 'line2']
|
||||
serialized = Marshal.dump(backtrace)
|
||||
compressed = Zlib::Deflate.deflate(serialized)
|
||||
encoded = Base64.encode64(compressed)
|
||||
|
||||
payload = Sidekiq.dump_json('class' => 'ApiWorker', 'args' => [1], 'queue' => 'default', 'jid' => 'jid', 'error_backtrace' => encoded)
|
||||
Sidekiq.redis do |conn|
|
||||
conn.zadd('retry', Time.now.to_f.to_s, payload)
|
||||
end
|
||||
|
||||
job = Sidekiq::RetrySet.new.first
|
||||
assert_equal backtrace, job.error_backtrace
|
||||
end
|
||||
|
||||
describe "Rails unwrapping" do
|
||||
SERIALIZED_JOBS = {
|
||||
"5.x" => [
|
||||
|
|
Loading…
Reference in a new issue