Class: SidekiqUniqueJobs::UpgradeLocks

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

Overview

Upgrades locks between gem version upgrades

Author:

Constant Summary collapse

BATCH_SIZE =

Returns the number of keys to batch upgrade.

Returns:

  • (Integer)

    the number of keys to batch upgrade

100
OLD_SUFFIXES =

Returns suffixes for old version.

Returns:

  • (Array<String>)

    suffixes for old version

%w[
  GRABBED
  AVAILABLE
  EXISTS
  VERSION
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Connection

included, #redis

Methods included from Logging

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

Constructor Details

#initialize(conn) ⇒ UpgradeLocks

Returns a new instance of UpgradeLocks.



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

def initialize(conn)
  @count         = 0
  @conn          = conn
  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/upgrade_locks.rb', line 37

def conn
  @conn
end

Class Method Details

.callInteger

Performs upgrade of old locks

Returns:

  • (Integer)

    the number of upgrades locks



31
32
33
34
35
# File 'lib/sidekiq_unique_jobs/upgrade_locks.rb', line 31

def self.call
  redis do |conn|
    new(conn).call
  end
end

Instance Method Details

#callInteger

Performs upgrade of old locks

Returns:

  • (Integer)

    the number of upgrades locks



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sidekiq_unique_jobs/upgrade_locks.rb', line 51

def call
  with_logging_context do
    return log_info("Already upgraded to #{version}") if conn.hget(upgraded_key, version)
    # TODO: Needs handling of v7.0.0 => v7.0.1 where we don't want to
    return log_info("Skipping upgrade because #{DEAD_VERSION} has been set") if conn.get(DEAD_VERSION)

    log_info("Start - Upgrading Locks")

    # upgrade_v6_locks
    # delete_unused_v6_keys
    # delete_supporting_v6_keys

    conn.hset(upgraded_key, version, now_f)
    log_info("Done - Upgrading Locks")
  end

  @count
end