class Sidetiq::Lock::MetaData

Constants

OWNER

Attributes

key[RW]
owner[RW]
timestamp[RW]

Public Class Methods

for_new_lock(key) click to toggle source
# File lib/sidetiq/lock/meta_data.rb, line 11
def for_new_lock(key)
  new(owner: OWNER, timestamp: Sidetiq.clock.gettime.to_f, key: key)
end
from_json(json = "") click to toggle source
# File lib/sidetiq/lock/meta_data.rb, line 15
def from_json(json = "")
  # Avoid TypeError when nil is passed to Sidekiq.load_json.
  json = "" if json.nil?

  hash = Sidekiq.load_json(json).symbolize_keys
  new(hash)
rescue StandardError => e
  if json != ""
    # Looks like garbage lock metadata, so report it.
    handle_exception(e, context: "Garbage lock meta data detected: #{json}")
  end

  new
end
new(hash = {}) click to toggle source
# File lib/sidetiq/lock/meta_data.rb, line 31
def initialize(hash = {})
  @owner = hash[:owner]
  @timestamp = hash[:timestamp]
  @key = hash[:key]
end

Public Instance Methods

pttl() click to toggle source
# File lib/sidetiq/lock/meta_data.rb, line 37
def pttl
  Sidekiq.redis { |r| r.pttl(key) }
end
to_json() click to toggle source
# File lib/sidetiq/lock/meta_data.rb, line 41
def to_json
  instance_variables.each_with_object({}) do |var, hash|
    hash[var.to_s.delete("@")] = instance_variable_get(var)
  end.to_json
end
to_s() click to toggle source
# File lib/sidetiq/lock/meta_data.rb, line 47
def to_s
  "Sidetiq::Lock on #{key} set at #{timestamp} by #{owner}"
end