diff --git a/lib/sidetiq/lock/meta_data.rb b/lib/sidetiq/lock/meta_data.rb index e5cd030..a22042f 100644 --- a/lib/sidetiq/lock/meta_data.rb +++ b/lib/sidetiq/lock/meta_data.rb @@ -44,13 +44,6 @@ module Sidetiq end.to_json end - def stale? - pttl_cached = pttl - - pttl_cached < 0 || pttl_cached >= Sidetiq.config.lock_expire || - timestamp < (Sidetiq.clock.gettime.to_i - 60) - end - def to_s "Sidetiq::Lock on #{key} set at #{timestamp} by #{owner}" end diff --git a/lib/sidetiq/lock/redis.rb b/lib/sidetiq/lock/redis.rb index d9fe538..d86a1b3 100644 --- a/lib/sidetiq/lock/redis.rb +++ b/lib/sidetiq/lock/redis.rb @@ -35,6 +35,16 @@ module Sidetiq end end + def stale? + pttl = meta_data.pttl + + # Consider PTTL of -1 (never set) and larger than the + # configured lock_expire as invalid. Locks with timestamps + # older than 1 minute are also considered stale. + pttl < 0 || pttl >= Sidetiq.config.lock_expire || + meta_data.timestamp < (Sidetiq.clock.gettime.to_i - 60) + end + def meta_data @meta_data ||= Sidekiq.redis do |redis| MetaData.from_json(redis.get(key)) diff --git a/lib/sidetiq/views/sidetiq_locks.erb b/lib/sidetiq/views/sidetiq_locks.erb index ef3e184..3c9e8e7 100644 --- a/lib/sidetiq/views/sidetiq_locks.erb +++ b/lib/sidetiq/views/sidetiq_locks.erb @@ -24,7 +24,7 @@ <% @locks.each do |meta| %> <% pttl = meta.pttl %> - + <%= meta.key %> <%= meta.owner %> <%= meta.timestamp.to_i %>