Module: Karafka::Pro::Routing::Features::RecurringTasks::Topic

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

Overview

Topic extensions to be able to check if given topic is a recurring tasks topic Please note, that this applies to both the schedules topics and reports topics

Instance Method Summary collapse

Instance Method Details

#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.



43
44
45
46
# File 'lib/karafka/pro/routing/features/recurring_tasks/topic.rb', line 43

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

#recurring_tasks(active = false) ⇒ Object

Parameters:

  • active (Boolean) (defaults to: false)

    should this topic be considered related to recurring tasks



49
50
51
# File 'lib/karafka/pro/routing/features/recurring_tasks/topic.rb', line 49

def recurring_tasks(active = false)
  @recurring_tasks ||= Config.new(active: active)
end

#recurring_tasks?Boolean

Returns is this an ActiveJob topic.

Returns:

  • (Boolean)

    is this an ActiveJob topic



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

def recurring_tasks?
  recurring_tasks.active?
end

#to_hHash

Returns topic with all its native configuration options plus active job namespace settings.

Returns:

  • (Hash)

    topic with all its native configuration options plus active job namespace settings



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

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