Class: Karafka::Pro::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/pro/loader.rb

Overview

Loader requires and loads all the pro components only when they are needed

Constant Summary collapse

FORCE_LOADED =

There seems to be a conflict in between using two Zeitwerk instances and it makes lookups for nested namespaces instead of creating them. We require those not to deal with this and then all works as expected

%w[
  active_job/dispatcher
  processing/jobs/consume_non_blocking
  processing/strategies/base
  routing/features/base
  encryption
  encryption/cipher
  encryption/setup/config
  encryption/contracts/config
  encryption/messages/parser
  cli/topics
].freeze

Class Method Summary collapse

Class Method Details

.post_fork(config, pre_fork_producer) ⇒ Object

Runs operations needed after fork in swarm for features that need it

Parameters:

  • config (Karafka::Core::Configurable::Node)
  • pre_fork_producer (WaterDrop::Producer)

    pre fork producer instance that may be needed to be replaced with newly changed one post-fork.



94
95
96
# File 'lib/karafka/pro/loader.rb', line 94

def post_fork(config, pre_fork_producer)
  features.each { |feature| feature.post_fork(config, pre_fork_producer) }
end

.post_setup_all(config) ⇒ Object

Runs post setup features configuration operations

Parameters:

  • config (Karafka::Core::Configurable::Node)


82
83
84
85
86
87
# File 'lib/karafka/pro/loader.rb', line 82

def post_setup_all(config)
  features.each { |feature| feature.post_setup(config) }

  # We initialize it here so we don't initialize it during multi-threading work
  Processing::SubscriptionGroupsCoordinator.instance
end

.pre_setup_all(config) ⇒ Object

Loads all the pro components and configures them wherever it is expected

Parameters:

  • config (Karafka::Core::Configurable::Node)

    app config that we can alter with pro components



70
71
72
73
74
75
76
77
# File 'lib/karafka/pro/loader.rb', line 70

def pre_setup_all(config)
  features.each { |feature| feature.pre_setup(config) }

  reconfigure(config)
  expand

  load_topic_features
end

.require_allObject

Requires all the components without using them anywhere



59
60
61
62
63
64
65
# File 'lib/karafka/pro/loader.rb', line 59

def require_all
  FORCE_LOADED.each { |file| require_relative(file) }

  PRO_LOADER.push_dir(Karafka.core_root.join("pro"), namespace: Karafka::Pro)
  PRO_LOADER.setup
  PRO_LOADER.eager_load
end