Module: GoodJob::ActiveJobExtensions::Concurrency

Extended by:
ActiveSupport::Concern
Defined in:
lib/good_job/active_job_extensions/concurrency.rb

Defined Under Namespace

Modules: Prepends Classes: ConcurrencyExceededError

Constant Summary collapse

VALID_TYPES =
[String, Symbol, Numeric, Date, Time, TrueClass, FalseClass, NilClass].freeze
ThrottleExceededError =
Class.new(ConcurrencyExceededError)

Instance Method Summary collapse

Instance Method Details

#_good_job_concurrency_keyObject

Generates the concurrency key from the configuration

Returns:

  • (Object)

    concurrency key

Raises:

  • (TypeError)


125
126
127
128
129
130
131
132
133
134
135
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 125

def _good_job_concurrency_key
  return _good_job_default_concurrency_key unless self.class.good_job_concurrency_config.key?(:key)

  key = self.class.good_job_concurrency_config[:key]
  return if key.blank?

  key = instance_exec(&key) if key.respond_to?(:call)
  raise TypeError, "Concurrency key must be a String; was a #{key.class}" unless VALID_TYPES.any? { |type| key.is_a?(type) }

  key
end

#_good_job_default_concurrency_keyString

Generates the default concurrency key when the configuration doesn’t provide one

Returns:

  • (String)

    concurrency key



139
140
141
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 139

def _good_job_default_concurrency_key
  self.class.name.to_s
end

#good_job_concurrency_keyObject

Existing or dynamically generated concurrency key

Returns:

  • (Object)

    concurrency key



119
120
121
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 119

def good_job_concurrency_key
  @good_job_concurrency_key || _good_job_concurrency_key
end