Module: Karafka::Pro::Routing::Features::LongRunningJob::Topic

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

Overview

Long-Running Jobs topic API extensions

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.



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

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

#long_running_job(active = false) ⇒ Object Also known as: long_running

Parameters:

  • active (Boolean) (defaults to: false)

    do we want to enable long-running job feature for this topic



40
41
42
# File 'lib/karafka/pro/routing/features/long_running_job/topic.rb', line 40

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

#long_running_job?Boolean

Returns is a given job on a topic a long-running one.

Returns:

  • (Boolean)

    is a given job on a topic a long-running one



47
48
49
# File 'lib/karafka/pro/routing/features/long_running_job/topic.rb', line 47

def long_running_job?
  long_running_job.active?
end

#to_hHash

Returns topic with all its native configuration options plus lrj.

Returns:

  • (Hash)

    topic with all its native configuration options plus lrj



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

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