Class: SidekiqUniqueJobs::Lock::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/lock/validator.rb

Overview

Validator base class to avoid some duplication

Author:

Constant Summary collapse

DEPRECATED_KEYS =

Returns a hash mapping of deprecated keys and their new value.

Returns:

  • (Hash)

    a hash mapping of deprecated keys and their new value

{
  UNIQUE.to_sym => LOCK.to_sym,
  UNIQUE_ARGS.to_sym => LOCK_ARGS_METHOD.to_sym,
  LOCK_ARGS.to_sym => LOCK_ARGS_METHOD.to_sym,
  UNIQUE_PREFIX.to_sym => LOCK_PREFIX.to_sym,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Validator

Initialize a new validator

Parameters:

  • options (Hash)

    the sidekiq_options for the worker being validated



41
42
43
44
45
# 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

Instance Attribute Details

#lock_configObject (readonly)

Returns the value of attribute lock_config.



34
35
36
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 34

def lock_config
  @lock_config
end

Class Method Details

.validate(options) ⇒ LockConfig

Shorthand for ‘new(options).validate`

Parameters:

  • options (Hash)

    the sidekiq_options for the worker being validated

Returns:

  • (LockConfig)

    the lock configuration with errors if any



27
28
29
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 27

def self.validate(options)
  new(options).validate
end

Instance Method Details

#handle_deprecationsvoid

This method returns an undefined value.

Validate deprecated keys

adds useful information about how to proceed with fixing handle_deprecations


73
74
75
76
77
78
79
# 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

#validateLockConfig

Validate the workers lock configuration

Returns:

  • (LockConfig)

    the lock configuration with errors if any



53
54
55
56
57
58
59
60
61
62
63
64
65
# 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_clientObject

Validates the client configuration



84
85
86
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 84

def validate_client
  ClientValidator.validate(lock_config)
end

#validate_serverObject

Validates the server configuration



91
92
93
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 91

def validate_server
  ServerValidator.validate(lock_config)
end