module Sidekiq::Component

def default_tag(dir = Dir.pwd)

def default_tag(dir = Dir.pwd)
  name = File.basename(dir)
  prevdir = File.dirname(dir) # Capistrano release directory?
  if name.to_i != 0 && prevdir
    if File.basename(prevdir) == "releases"
      return File.basename(File.dirname(prevdir))
    end
  end
  name
end

def fire_event(event, options = {})

def fire_event(event, options = {})
  oneshot = options.fetch(:oneshot, true)
  reverse = options[:reverse]
  reraise = options[:reraise]
  logger.debug("Firing #{event} event") if oneshot
  arr = config[:lifecycle_events][event]
  arr.reverse! if reverse
  arr.each do |block|
    block.call
  rescue => ex
    handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event})
    raise ex if reraise
  end
  arr.clear if oneshot # once we've fired an event, we never fire it again
end

def handle_exception(ex, ctx = {})

def handle_exception(ex, ctx = {})
  config.handle_exception(ex, ctx)
end

def hostname

def hostname
  ENV["DYNO"] || Socket.gethostname
end

def identity

def identity
  @@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}"
end

def inspect

state and use `to_s` instead to keep output manageable, #6553
references everywhere. We avoid calling `inspect` on more complex
can get out of hand, especially with lots of Sidekiq::Config
When you have a large tree of components, the `inspect` output
def inspect
  "#<#{self.class.name} #{
    instance_variables.map do |name|
      value = instance_variable_get(name)
      case value
      when Proc
        "#{name}=#{value}"
      when Sidekiq::Config
        "#{name}=#{value}"
      when Sidekiq::Component
        "#{name}=#{value}"
      else
        "#{name}=#{value.inspect}"
      end
    end.join(", ")
  }>"
end

def logger

def logger
  config.logger
end

def mono_ms

used for time difference and relative comparisons, not persistence.
def mono_ms
  ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :millisecond)
end

def process_nonce

def process_nonce
  @@process_nonce ||= SecureRandom.hex(6)
end

def real_ms

This is epoch milliseconds, appropriate for persistence
def real_ms
  ::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond)
end

def redis(&block)

def redis(&block)
  config.redis(&block)
end

def safe_thread(name, priority: nil, &block)

def safe_thread(name, priority: nil, &block)
  Thread.new do
    Thread.current.name = "sidekiq.#{name}"
    watchdog(name, &block)
  end.tap { |t| t.priority = (priority || config.thread_priority || DEFAULT_THREAD_PRIORITY) }
end

def tid

def tid
  Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
end

def watchdog(last_words)

def watchdog(last_words)
  yield
rescue Exception => ex
  handle_exception(ex, {context: last_words})
  raise ex
end