Sha256: 9b2407aafee3b4f0d69b489ac4f770bb875b41ca354482ef4ac11ff30b485ca5

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Karafka
  # Additional callbacks that are used to trigger some things in given places during the
  # system lifecycle
  # @note Those callbacks aren't the same as consumer callbacks as they are not related to the
  #   lifecycle of particular messages fetches but rather to the internal flow process.
  #   They cannot be defined on a consumer callback level because for some of those,
  #   there aren't consumers in the memory yet and/or they aren't per consumer thread
  module Callbacks
    # Types of system callbacks that we have that are not related to consumers
    TYPES = %i[
      after_init
      before_fetch_loop
    ].freeze

    class << self
      TYPES.each do |callback_type|
        # Executes given callbacks set at a given moment with provided arguments
        define_method callback_type do |*args|
          Karafka::App
            .config
            .callbacks
            .send(callback_type)
            .each { |block| block.call(*args) }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
karafka-1.2.0.beta2 lib/karafka/callbacks.rb
karafka-1.2.0.beta1 lib/karafka/callbacks.rb