mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Ensure TID changes after fork, fixes #3685
This commit is contained in:
parent
515b294dca
commit
5315e09c56
4 changed files with 17 additions and 9 deletions
|
@ -11,7 +11,7 @@ module Sidekiq
|
|||
|
||||
# Provide a call() method that returns the formatted message.
|
||||
def call(severity, time, program_name, message)
|
||||
"#{time.utc.iso8601(3)} #{::Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{context} #{severity}: #{message}\n"
|
||||
"#{time.utc.iso8601(3)} #{::Process.pid} TID-#{Sidekiq::Util.tid}#{context} #{severity}: #{message}\n"
|
||||
end
|
||||
|
||||
def context
|
||||
|
@ -22,7 +22,7 @@ module Sidekiq
|
|||
|
||||
class WithoutTimestamp < Pretty
|
||||
def call(severity, time, program_name, message)
|
||||
"#{::Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{context} #{severity}: #{message}\n"
|
||||
"#{::Process.pid} TID-#{Sidekiq::Util.tid}#{context} #{severity}: #{message}\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -186,16 +186,12 @@ module Sidekiq
|
|||
worker.perform(*cloned_args)
|
||||
end
|
||||
|
||||
def thread_identity
|
||||
@str ||= Thread.current.object_id.to_s(36)
|
||||
end
|
||||
|
||||
WORKER_STATE = Concurrent::Map.new
|
||||
PROCESSED = Concurrent::AtomicFixnum.new
|
||||
FAILURE = Concurrent::AtomicFixnum.new
|
||||
|
||||
def stats(job_hash, queue)
|
||||
tid = thread_identity
|
||||
tid = Sidekiq::Util.tid
|
||||
WORKER_STATE[tid] = {:queue => queue, :payload => job_hash, :run_at => Time.now.to_i }
|
||||
|
||||
begin
|
||||
|
|
|
@ -12,6 +12,10 @@ module Sidekiq
|
|||
|
||||
EXPIRY = 60 * 60 * 24
|
||||
|
||||
def self.tid
|
||||
Thread.current['sidekiq_tid'] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
|
||||
end
|
||||
|
||||
def watchdog(last_words)
|
||||
yield
|
||||
rescue Exception => ex
|
||||
|
|
|
@ -7,7 +7,15 @@ class TestUtil < Sidekiq::Test
|
|||
include Sidekiq::Util
|
||||
end
|
||||
|
||||
def test_nothing_atm
|
||||
assert true
|
||||
def test_tid
|
||||
x = Sidekiq::Util.tid
|
||||
y = nil
|
||||
t = Thread.new do
|
||||
Sidekiq::Util.tid
|
||||
end
|
||||
y = t.value
|
||||
assert x
|
||||
assert y
|
||||
refute_equal x, y
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue