Class: SidekiqUniqueJobs::Reflections

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

Overview

Class NotificationCollection provides a collection with known notifications

Author:

Constant Summary collapse

REFLECTIONS =

Returns list of notifications.

Returns:

  • (Array<Symbol>)

    list of notifications

[
  :after_unlock_callback_failed,
  :debug,
  :duplicate,
  :error,
  :execution_failed,
  :lock_failed,
  :locked,
  :reschedule_failed,
  :rescheduled,
  :timeout,
  :unknown_sidekiq_worker,
  :unlock_failed,
  :unlocked,
].freeze
DEPRECATIONS =

Returns a hash with deprecated notifications.

Returns:

  • (Hash<Symbol, Array<Symbol, String>>)

    a hash with deprecated notifications

{}.freeze

Instance Method Summary collapse

Constructor Details

#initializeReflections

Returns a new instance of Reflections.



41
42
43
# File 'lib/sidekiq_unique_jobs/reflections.rb', line 41

def initialize
  @reflections = {}
end

Instance Method Details

#configured?(reflection) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/sidekiq_unique_jobs/reflections.rb', line 71

def configured?(reflection)
  REFLECTIONS.include?(reflection)
end

#dispatch(reflection, *args) ⇒ void

This method returns an undefined value.

Dispatch a reflected event

Parameters:

  • reflection (reflection)

    the reflected event

  • args (Array)

    the arguments to provide to the block



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

def dispatch(reflection, *args) # rubocop:disable Metrics/MethodLength
  if (block = @reflections[reflection])
    block.call(*args)

    if DEPRECATIONS.key?(reflection)
      replacement, removal_version = DEPRECATIONS[reflection]
      SidekiqUniqueJobs::Deprecation.warn(
        "#{reflection} is deprecated and will be removed in version #{removal_version}." \
        " Use #{replacement} instead.",
      )
    end
  elsif misconfigured?(reflection)
    raise NoSuchNotificationError, reflection
  end

  nil
end

#misconfigured?(reflection) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/sidekiq_unique_jobs/reflections.rb', line 75

def misconfigured?(reflection)
  !configured?(reflection)
end