Class: SidekiqUniqueJobs::BatchDelete

Inherits:
Object
  • Object
show all
Includes:
Connection, Logging
Defined in:
lib/sidekiq_unique_jobs/batch_delete.rb

Overview

Class BatchDelete provides batch deletion of digests

Author:

Constant Summary collapse

BATCH_SIZE =

Returns the default batch size.

Returns:

  • (Integer)

    the default batch size

100
SUFFIXES =

Returns Supported key suffixes.

Returns:

  • (Array<String>)

    Supported key suffixes

%w[
  QUEUED
  PRIMED
  LOCKED
  INFO
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 Connection

included, #redis

Constructor Details

#initialize(digests, conn) ⇒ BatchDelete

Initialize a new batch delete instance

Parameters:

  • digests (Array<String>)

    the digests to delete

  • conn (Redis)

    the connection to use for deletion



57
58
59
60
61
62
63
64
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 57

def initialize(digests, conn)
  @count   = 0
  @digests = digests
  @conn    = conn
  @digests ||= []
  @digests.compact!
  redis_version # Avoid pipelined calling redis_version and getting a future.
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



37
38
39
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 37

def conn
  @conn
end

#digestsObject (readonly)

Returns the value of attribute digests.



33
34
35
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 33

def digests
  @digests
end

Class Method Details

.call(digests, conn = nil) ⇒ void

This method returns an undefined value.

Executes a batch deletion of the provided digests

Parameters:

  • digests (Array<String>)

    the digests to delete

  • conn (Redis) (defaults to: nil)

    the connection to use for deletion



47
48
49
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 47

def self.call(digests, conn = nil)
  new(digests, conn).call
end

Instance Method Details

#callObject

Note:

Just wraps batch_delete to be able to provide no connection

Executes a batch deletion of the provided digests



71
72
73
74
75
76
77
78
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 71

def call
  return log_info("Nothing to delete; exiting.") if digests.none?

  log_info("Deleting batch with #{digests.size} digests")
  return batch_delete(conn) if conn

  redis { |rcon| batch_delete(rcon) }
end