Class: SidekiqUniqueJobs::Orphans::Reaper

Inherits:
Object
  • Object
show all
Includes:
Connection, JSON, Logging, Script::Caller
Defined in:
lib/sidekiq_unique_jobs/orphans/reaper.rb

Overview

Note:

this is a much slower version of the lua script but does not crash redis

Class DeleteOrphans provides deletion of orphaned digests

Author:

Direct Known Subclasses

LuaReaper, NullReaper, RubyReaper

Constant Summary collapse

REAPERS =

Returns Hash<Symbol, SidekiqUniqueJobs::Orphans::Reaper] the current implementation of reapers.

Returns:

{
  lua: SidekiqUniqueJobs::Orphans::LuaReaper,
  ruby: SidekiqUniqueJobs::Orphans::RubyReaper,
  none: SidekiqUniqueJobs::Orphans::NullReaper,
  nil => SidekiqUniqueJobs::Orphans::NullReaper,
  false => SidekiqUniqueJobs::Orphans::NullReaper,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSON

dump_json, load_json, safe_load_json

Methods included from Logging

#build_message, included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context

Methods included from Script::Caller

call_script, debug_lua, do_call, extract_args, max_history, normalize_argv, now_f, redis_version

Methods included from Connection

included, #redis

Constructor Details

#initialize(conn) ⇒ Reaper

Initialize a new instance of DeleteOrphans

Parameters:

  • conn (Redis)

    a connection to redis



55
56
57
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 55

def initialize(conn)
  @conn = conn
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



48
49
50
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 48

def conn
  @conn
end

Class Method Details

.call(conn = nil) ⇒ void

This method returns an undefined value.

Execute deletion of orphaned digests

Parameters:

  • conn (Redis) (defaults to: nil)

    nil a connection to redis



39
40
41
42
43
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 39

def self.call(conn = nil)
  return new(conn).call if conn

  redis { |rcon| new(rcon).call }
end

Instance Method Details

#callInteger

Delete orphaned digests

Returns:

  • (Integer)

    the number of reaped locks



105
106
107
108
109
110
111
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 105

def call
  if (implementation = REAPERS[reaper])
    implementation.new(conn).call
  else
    log_fatal(":#{reaper} is invalid for `SidekiqUnqiueJobs.config.reaper`")
  end
end

#configSidekiqUniqueJobs::Config

Convenient access to the global configuration



65
66
67
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 65

def config
  SidekiqUniqueJobs.config
end

#reaperSymbol

The reaper that was configured

Returns:

  • (Symbol)


75
76
77
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 75

def reaper
  config.reaper
end

#reaper_countInteger

The number of locks to reap at a time

Returns:

  • (Integer)


95
96
97
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 95

def reaper_count
  config.reaper_count
end

#reaper_timeoutInteger

The configured timeout for the reaper

Returns:

  • (Integer)

    timeout in seconds



85
86
87
# File 'lib/sidekiq_unique_jobs/orphans/reaper.rb', line 85

def reaper_timeout
  config.reaper_timeout
end