Module: Karafka::Pro::Routing::Features::Delaying::Topic

Defined in:
lib/karafka/pro/routing/features/delaying/topic.rb

Overview

Topic delaying API extensions

Instance Method Summary collapse

Instance Method Details

#delay_byObject

Just an alias for nice API



55
56
57
# File 'lib/karafka/pro/routing/features/delaying/topic.rb', line 55

def delay_by(*)
  delaying(*)
end

#delaying(delay = nil) ⇒ Object

Parameters:

  • delay (Integer, nil) (defaults to: nil)

    minimum age of a message we want to process



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/karafka/pro/routing/features/delaying/topic.rb', line 40

def delaying(delay = nil)
  # Those settings are used for validation
  @delaying ||= begin
    config = Config.new(active: !delay.nil?, delay: delay)

    if config.active?
      factory = ->(*) { Pro::Processing::Filters::Delayer.new(delay) }
      filter(factory)
    end

    config
  end
end

#delaying?Boolean

Returns is a given job delaying.

Returns:

  • (Boolean)

    is a given job delaying



60
61
62
# File 'lib/karafka/pro/routing/features/delaying/topic.rb', line 60

def delaying?
  delaying.active?
end

#initializeObject

This method calls the parent class initializer and then sets up the extra instance variable to nil. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.



34
35
36
37
# File 'lib/karafka/pro/routing/features/delaying/topic.rb', line 34

def initialize(...)
  super
  @delaying = nil
end

#to_hHash

Returns topic with all its native configuration options plus delaying.

Returns:

  • (Hash)

    topic with all its native configuration options plus delaying



65
66
67
68
69
# File 'lib/karafka/pro/routing/features/delaying/topic.rb', line 65

def to_h
  super.merge(
    delaying: delaying.to_h
  ).freeze
end