Class: Kaal::Configuration
- Inherits:
-
Object
- Object
- Kaal::Configuration
- Defined in:
- lib/kaal/config/configuration.rb
Overview
Configuration class for Kaal Holds all settings for the scheduler, tick intervals, locks, and more.
Constant Summary collapse
- DEFAULTS =
Default values for all configuration options
{ tick_interval: 5, window_lookback: 120, window_lookahead: 0, lease_ttl: 125, # Must be >= window_lookback + tick_interval (120 + 5 = 125) namespace: 'kaal', backend: nil, logger: nil, time_zone: nil, enable_log_dispatch_registry: false, enable_dispatch_recovery: true, recovery_window: 86_400, # 24 hours in seconds recovery_startup_jitter: 5, # max random delay in seconds scheduler_config_path: 'config/scheduler.yml', scheduler_conflict_policy: :error, scheduler_missing_file_policy: :warn, delayed_job_allowed_class_prefixes: [] }.freeze
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Initialize a new Configuration instance with default values.
-
#method_missing(method_name, *args) ⇒ Object
Retrieve or assign configuration values by method name.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Advertise supported configuration keys for respond_to?.
-
#to_h ⇒ Hash
Get a hash representation of the current configuration.
-
#validate ⇒ Array<String>
Validate configuration without raising.
-
#validate! ⇒ Configuration
Validate the configuration settings.
-
#validation_warnings ⇒ Array<String>
Non-fatal configuration warnings.
Constructor Details
#initialize ⇒ Configuration
Initialize a new Configuration instance with default values.
42 43 44 |
# File 'lib/kaal/config/configuration.rb', line 42 def initialize @values = DEFAULTS.dup end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Retrieve or assign configuration values by method name.
48 49 50 51 52 53 54 55 56 |
# File 'lib/kaal/config/configuration.rb', line 48 def method_missing(method_name, *args) handled, value = handle_known_key(method_name) do |key, setter| setter ? set_value(key, args.first) : @values[key] end return value if handled super end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Advertise supported configuration keys for respond_to?.
60 61 62 63 |
# File 'lib/kaal/config/configuration.rb', line 60 def respond_to_missing?(method_name, include_private = false) handled, value = handle_known_key(method_name) { true } (handled && value) || super end |
#to_h ⇒ Hash
Get a hash representation of the current configuration.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/kaal/config/configuration.rb', line 103 def to_h backend = @values[:backend] logger = @values[:logger] { tick_interval: @values[:tick_interval], window_lookback: @values[:window_lookback], window_lookahead: @values[:window_lookahead], lease_ttl: @values[:lease_ttl], namespace: @values[:namespace], backend: backend&.class&.name, logger: logger&.class&.name, time_zone: @values[:time_zone], enable_log_dispatch_registry: @values[:enable_log_dispatch_registry], enable_dispatch_recovery: @values[:enable_dispatch_recovery], recovery_window: @values[:recovery_window], recovery_startup_jitter: @values[:recovery_startup_jitter], scheduler_config_path: @values[:scheduler_config_path], scheduler_conflict_policy: @values[:scheduler_conflict_policy], scheduler_missing_file_policy: @values[:scheduler_missing_file_policy], delayed_job_allowed_class_prefixes: @values[:delayed_job_allowed_class_prefixes] } end |
#validate ⇒ Array<String>
Validate configuration without raising.
69 70 71 |
# File 'lib/kaal/config/configuration.rb', line 69 def validate validation_errors end |
#validate! ⇒ Configuration
Validate the configuration settings. Raises errors if required settings are invalid.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kaal/config/configuration.rb', line 88 def validate! errors = validation_errors raise ConfigurationError, errors.join('; ') if errors.any? validation_warnings.each do |warning| @values[:logger]&.warn(warning) end self end |
#validation_warnings ⇒ Array<String>
Non-fatal configuration warnings.
76 77 78 79 80 |
# File 'lib/kaal/config/configuration.rb', line 76 def validation_warnings warnings = [] add_delayed_job_security_warning(warnings) warnings end |