Class: Tasker::Registry::BaseRegistry

Inherits:
Object
  • Object
show all
Includes:
Concerns::StructuredLogging
Defined in:
lib/tasker/registry/base_registry.rb

Overview

Base class for all registry systems in Tasker

Provides common functionality including thread-safe operations, structured logging, health checks, and statistics interfaces. All registry classes should inherit from this base class.

Constant Summary

Constants included from Concerns::StructuredLogging

Concerns::StructuredLogging::CORRELATION_ID_KEY

Instance Method Summary collapse

Methods included from Concerns::StructuredLogging

#correlation_id, #correlation_id=, #log_exception, #log_orchestration_event, #log_performance_event, #log_step_event, #log_structured, #log_task_event, #with_correlation_id

Constructor Details

#initializeBaseRegistry

Returns a new instance of BaseRegistry.



17
18
19
20
21
22
# File 'lib/tasker/registry/base_registry.rb', line 17

def initialize
  @mutex = Mutex.new
  @telemetry_config = Tasker::Configuration.configuration.telemetry
  @registry_name = self.class.name.demodulize.underscore
  @created_at = Time.current
end

Instance Method Details

#all_itemsHash

Get all items in the registry

Returns:

  • (Hash)

    All registered items

Raises:

  • (NotImplementedError)

    Must be implemented by subclasses



164
165
166
# File 'lib/tasker/registry/base_registry.rb', line 164

def all_items
  raise NotImplementedError, 'Subclasses must implement #all_items'
end

#base_statsHash (protected)

Common registry statistics interface

Returns:

  • (Hash)

    Base statistics shared by all registries



120
121
122
123
124
125
126
# File 'lib/tasker/registry/base_registry.rb', line 120

def base_stats
  {
    registry_name: @registry_name,
    created_at: @created_at,
    uptime_seconds: (Time.current - @created_at).to_i
  }
end

#clear!void

This method returns an undefined value.

Clear all items from the registry

Raises:

  • (NotImplementedError)

    Must be implemented by subclasses



172
173
174
# File 'lib/tasker/registry/base_registry.rb', line 172

def clear!
  raise NotImplementedError, 'Subclasses must implement #clear!'
end

#health_checkHash (protected)

Comprehensive health check with details

Returns:

  • (Hash)

    Health check results



139
140
141
142
143
144
145
146
# File 'lib/tasker/registry/base_registry.rb', line 139

def health_check
  {
    healthy: healthy?,
    registry_name: @registry_name,
    stats: stats,
    last_check: Time.current
  }
end

#healthy?Boolean (protected)

Health check interface

Returns:

  • (Boolean)

    True if registry is healthy



131
132
133
134
# File 'lib/tasker/registry/base_registry.rb', line 131

def healthy?
  # Basic health checks that all registries should pass
  !@mutex.locked? && respond_to?(:stats)
end

#log_registration(entity_type, entity_id, entity_class, options = {}) ⇒ Object (protected)

Log registration events with structured format

Parameters:

  • entity_type (String)

    Type of entity being registered

  • entity_id (String)

    Unique identifier for the entity

  • entity_class (Class, String)

    Class of the entity being registered

  • options (Hash) (defaults to: {})

    Additional registration options



32
33
34
35
36
37
38
39
40
41
# File 'lib/tasker/registry/base_registry.rb', line 32

def log_registration(entity_type, entity_id, entity_class, options = {})
  class_name = entity_class.is_a?(Class) ? entity_class.name : entity_class.to_s
  log_structured(:info, 'Registry item registered',
                 entity_type: entity_type,
                 entity_id: entity_id,
                 entity_class: class_name,
                 registry_name: @registry_name,
                 options: options,
                 event_type: :registered)
end

#log_registry_error(operation, error, **context) ⇒ Object (protected)

Log registry errors with structured format

Parameters:

  • operation (String)

    Operation that failed

  • error (Exception)

    The error that occurred

  • context (Hash)

    Additional context for the error



74
75
76
77
78
79
80
81
# File 'lib/tasker/registry/base_registry.rb', line 74

def log_registry_error(operation, error, **context)
  log_structured(:error, "Registry #{operation} failed",
                 registry_name: @registry_name,
                 operation: operation,
                 error: error.message,
                 error_class: error.class.name,
                 **context)
end

#log_registry_operation(operation, **context) ⇒ Object (protected)

Log registry operations with structured format

Parameters:

  • operation (String)

    Operation being performed

  • context (Hash)

    Additional context for the operation



62
63
64
65
66
67
# File 'lib/tasker/registry/base_registry.rb', line 62

def log_registry_operation(operation, **context)
  log_structured(:debug, "Registry #{operation}",
                 registry_name: @registry_name,
                 operation: operation,
                 **context)
end

#log_unregistration(entity_type, entity_id, entity_class) ⇒ Object (protected)

Log unregistration events with structured format

Parameters:

  • entity_type (String)

    Type of entity being unregistered

  • entity_id (String)

    Unique identifier for the entity

  • entity_class (Class, String)

    Class of the entity being unregistered



48
49
50
51
52
53
54
55
56
# File 'lib/tasker/registry/base_registry.rb', line 48

def log_unregistration(entity_type, entity_id, entity_class)
  class_name = entity_class.is_a?(Class) ? entity_class.name : entity_class.to_s
  log_structured(:info, 'Registry item unregistered',
                 entity_type: entity_type,
                 entity_id: entity_id,
                 entity_class: class_name,
                 registry_name: @registry_name,
                 event_type: :unregistered)
end

#log_validation_failure(entity_type, entity_id, validation_error) ⇒ Object (protected)

Log validation failures with structured format

Parameters:

  • entity_type (String)

    Type of entity that failed validation

  • entity_id (String)

    Unique identifier for the entity

  • validation_error (String)

    Description of the validation failure



88
89
90
91
92
93
94
95
# File 'lib/tasker/registry/base_registry.rb', line 88

def log_validation_failure(entity_type, entity_id, validation_error)
  log_structured(:error, 'Registry validation failed',
                 entity_type: entity_type,
                 entity_id: entity_id,
                 registry_name: @registry_name,
                 validation_error: validation_error,
                 event_type: :validation_failed)
end

#statsHash

Get comprehensive statistics for this registry

Returns:

  • (Hash)

    Registry-specific statistics

Raises:

  • (NotImplementedError)

    Must be implemented by subclasses



156
157
158
# File 'lib/tasker/registry/base_registry.rb', line 156

def stats
  raise NotImplementedError, 'Subclasses must implement #stats'
end

#thread_safe_operation { ... } ⇒ Object (protected)

Execute operations in a thread-safe manner

Yields:

  • Block to execute within mutex

Returns:

  • (Object)

    Result of the block



113
114
115
# File 'lib/tasker/registry/base_registry.rb', line 113

def thread_safe_operation(&)
  @mutex.synchronize(&)
end

#validate_registration_params!(name, entity_class, options = {}) ⇒ Object (protected)

Validate registration parameters

Parameters:

  • name (String)

    Name of the entity

  • entity_class (Class)

    Class of the entity

  • options (Hash) (defaults to: {})

    Registration options

Raises:

  • (ArgumentError)

    If parameters are invalid



103
104
105
106
107
# File 'lib/tasker/registry/base_registry.rb', line 103

def validate_registration_params!(name, entity_class, options = {})
  raise ArgumentError, 'Name cannot be blank' if name.blank?
  raise ArgumentError, 'Entity class cannot be nil' if entity_class.nil?
  raise ArgumentError, 'Options must be a Hash' unless options.is_a?(Hash)
end