Class: Karafka::Web::Ui::Models::Status::Checks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/ui/models/status/checks/base.rb

Overview

Base class for all status checks.

Provides a DSL for declaring check dependencies and characteristics, as well as common functionality for executing checks.

Examples:

Creating a simple independent check

class Enabled < Base
  independent!

  def call
    enabled = ::Karafka::App.routes.map(&:name).include?(
      ::Karafka::Web.config.group_id
    )
    step(enabled ? :success : :failure)
  end
end

Creating a dependent check

class Connection < Base
  depends_on :enabled

  def call
    # Implementation...
    step(:success, { time: context.connection_time })
  end
end

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Base

Initializes the check with a shared context.

Parameters:

  • context (Status::Context)

    the shared context containing cached data and configuration helpers



91
92
93
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 91

def initialize(context)
  @context = context
end

Class Attribute Details

.dependencySymbol? (readonly)

Returns the dependency check name, or nil if independent.

Returns:

  • (Symbol, nil)

    the dependency check name, or nil if independent



42
43
44
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 42

def dependency
  @dependency
end

Class Method Details

.depends_on(check_name) ⇒ Symbol

Declares that this check depends on another check.

When a check has a dependency, it will be halted if the dependency fails.

Examples:

class Connection < Base
  depends_on :enabled
end

Parameters:

  • check_name (Symbol)

    the name of the check this depends on

Returns:

  • (Symbol)

    the dependency name



55
56
57
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 55

def depends_on(check_name)
  @dependency = check_name
end

.halted_detailsHash, Array

Returns the halted details for this check.

Override this method in subclasses to provide specific details when the check is halted due to dependency failure.

Returns:

  • (Hash, Array)

    the default details for halted state



82
83
84
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 82

def halted_details
  {}
end

.independent!Boolean

Marks this check as independent (no dependencies).

Independent checks don’t depend on any other check and will always execute regardless of other check results.

Returns:

  • (Boolean)

    true



65
66
67
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 65

def independent!
  @independent = true
end

.independent?Boolean

Checks if this is an independent check.

Returns:

  • (Boolean)

    true if this check has no dependencies



72
73
74
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 72

def independent?
  @independent || false
end

Instance Method Details

#callStatus::Step

Executes the check and returns a Step result.

Subclasses must implement this method to perform the actual check.

Returns:

Raises:

  • (NotImplementedError)

    if not implemented by subclass



101
102
103
# File 'lib/karafka/web/ui/models/status/checks/base.rb', line 101

def call
  raise NotImplementedError, "Subclasses must implement #call"
end