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:

  • Mikael Henriksson <mikael@mhenrixon.com>

Constant Summary collapse

BATCH_SIZE =

Returns the default batch size.

Returns:

  • (Integer)

    the default batch size

500

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



48
49
50
51
52
53
54
55
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 48

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.



28
29
30
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 28

def conn
  @conn
end

#digestsObject (readonly)

Returns the value of attribute digests.



24
25
26
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 24

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



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

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



62
63
64
65
66
67
68
69
# File 'lib/sidekiq_unique_jobs/batch_delete.rb', line 62

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