class SidekiqUniqueJobs::Lock::Validator

Validator base class to avoid some duplication

@author Mikael Henriksson <mikael@mhenrixon.com>

Constants

DEPRECATED_KEYS

@return [Hash] a hash mapping of deprecated keys and their new value

Attributes

lock_config[R]

@!attribute [r] lock_config

@return [LockConfig] the lock configuration for this worker

Public Class Methods

new(options) click to toggle source

Initialize a new validator

@param [Hash] options the sidekiq_options for the worker being validated

# File lib/sidekiq_unique_jobs/lock/validator.rb, line 41
def initialize(options)
  @options     = options.transform_keys(&:to_sym)
  @lock_config = LockConfig.new(options)
  handle_deprecations
end
validate(options) click to toggle source

Shorthand for `new(options).validate`

@param [Hash] options the sidekiq_options for the worker being validated

@return [LockConfig] the lock configuration with errors if any

# File lib/sidekiq_unique_jobs/lock/validator.rb, line 27
def self.validate(options)
  new(options).validate
end

Public Instance Methods

handle_deprecations() click to toggle source

Validate deprecated keys

adds useful information about how to proceed with fixing handle_deprecations

@return [void]

# File lib/sidekiq_unique_jobs/lock/validator.rb, line 73
def handle_deprecations
  DEPRECATED_KEYS.each do |old, new|
    next unless @options.key?(old)

    lock_config.errors[old] = "is deprecated, use `#{new}: #{@options[old]}` instead."
  end
end
validate() click to toggle source

Validate the workers lock configuration

@return [LockConfig] the lock configuration with errors if any

# File lib/sidekiq_unique_jobs/lock/validator.rb, line 53
def validate
  case lock_config.type
  when :while_executing
    validate_server
  when :until_executing
    validate_client
  else
    validate_client
    validate_server
  end

  lock_config
end
validate_client() click to toggle source

Validates the client configuration

# File lib/sidekiq_unique_jobs/lock/validator.rb, line 84
def validate_client
  ClientValidator.validate(lock_config)
end
validate_server() click to toggle source

Validates the server configuration

# File lib/sidekiq_unique_jobs/lock/validator.rb, line 91
def validate_server
  ServerValidator.validate(lock_config)
end