Module: Karafka::ActiveJob::JobExtensions

Defined in:
lib/karafka/active_job/job_extensions.rb

Overview

Allows for setting karafka specific options in ActiveJob jobs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object

Defines all the needed accessors and sets defaults

Parameters:

  • klass (ActiveJob::Base)

    active job base



10
11
12
13
# File 'lib/karafka/active_job/job_extensions.rb', line 10

def extended(klass)
  klass.class_attribute :_karafka_options
  klass._karafka_options = {}
end

Instance Method Details

#karafka_options(new_options = {}) ⇒ Hash

Returns karafka options.

Parameters:

  • new_options (Hash) (defaults to: {})

    additional options that allow for jobs Karafka related options customization

Returns:

  • (Hash)

    karafka options



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/karafka/active_job/job_extensions.rb', line 19

def karafka_options(new_options = {})
  return _karafka_options if new_options.empty?

  # Make sure, that karafka options that someone wants to use are valid before assigning
  # them
  App.config.internal.active_job.job_options_contract.validate!(new_options)

  # We need to modify this hash because otherwise we would modify parent hash.
  self._karafka_options = _karafka_options.dup

  new_options.each do |name, value|
    _karafka_options[name] = value
  end

  _karafka_options
end