Class: Tasker::Registry::BaseRegistry
- Inherits:
-
Object
- Object
- Tasker::Registry::BaseRegistry
- 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.
Direct Known Subclasses
HandlerFactory, SubscriberRegistry, Telemetry::PluginRegistry
Constant Summary
Constants included from Concerns::StructuredLogging
Concerns::StructuredLogging::CORRELATION_ID_KEY
Instance Method Summary collapse
-
#all_items ⇒ Hash
Get all items in the registry.
-
#base_stats ⇒ Hash
protected
Common registry statistics interface.
-
#clear! ⇒ void
Clear all items from the registry.
-
#health_check ⇒ Hash
protected
Comprehensive health check with details.
-
#healthy? ⇒ Boolean
protected
Health check interface.
-
#initialize ⇒ BaseRegistry
constructor
A new instance of BaseRegistry.
-
#log_registration(entity_type, entity_id, entity_class, options = {}) ⇒ Object
protected
Log registration events with structured format.
-
#log_registry_error(operation, error, **context) ⇒ Object
protected
Log registry errors with structured format.
-
#log_registry_operation(operation, **context) ⇒ Object
protected
Log registry operations with structured format.
-
#log_unregistration(entity_type, entity_id, entity_class) ⇒ Object
protected
Log unregistration events with structured format.
-
#log_validation_failure(entity_type, entity_id, validation_error) ⇒ Object
protected
Log validation failures with structured format.
-
#stats ⇒ Hash
Get comprehensive statistics for this registry.
-
#thread_safe_operation { ... } ⇒ Object
protected
Execute operations in a thread-safe manner.
-
#validate_registration_params!(name, entity_class, options = {}) ⇒ Object
protected
Validate registration parameters.
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
#initialize ⇒ BaseRegistry
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_items ⇒ Hash
Get all items in the registry
164 165 166 |
# File 'lib/tasker/registry/base_registry.rb', line 164 def all_items raise NotImplementedError, 'Subclasses must implement #all_items' end |
#base_stats ⇒ Hash (protected)
Common registry statistics interface
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
172 173 174 |
# File 'lib/tasker/registry/base_registry.rb', line 172 def clear! raise NotImplementedError, 'Subclasses must implement #clear!' end |
#health_check ⇒ Hash (protected)
Comprehensive health check with details
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
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
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, = {}) 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: , event_type: :registered) end |
#log_registry_error(operation, error, **context) ⇒ Object (protected)
Log registry errors with structured format
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., error_class: error.class.name, **context) end |
#log_registry_operation(operation, **context) ⇒ Object (protected)
Log registry operations with structured format
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
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
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 |
#stats ⇒ Hash
Get comprehensive statistics for this registry
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
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
103 104 105 106 107 |
# File 'lib/tasker/registry/base_registry.rb', line 103 def validate_registration_params!(name, entity_class, = {}) 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 .is_a?(Hash) end |