Class: Tasker::Types::ExecutionConfig
- Inherits:
-
BaseConfig
- Object
- Dry::Struct
- BaseConfig
- Tasker::Types::ExecutionConfig
- Defined in:
- lib/tasker/types/execution_config.rb
Overview
Configuration type for step execution and concurrency settings
This configuration exposes previously hardcoded execution constants used in concurrent step processing, timeout handling, and memory management.
Strategic Design:
- CONFIGURABLE: Performance characteristics that vary by deployment environment
- ARCHITECTURAL: Carefully chosen constants based on Ruby/Rails characteristics
Instance Attribute Summary collapse
-
#batch_timeout_base_seconds ⇒ Integer
readonly
Base timeout in seconds (default: 30).
-
#batch_timeout_per_step_seconds ⇒ Integer
readonly
Per-step timeout in seconds (default: 5).
-
#concurrency_cache_duration ⇒ Integer
readonly
Cache duration in seconds (default: 30).
-
#connection_health_log_level ⇒ String
readonly
Log level (default: 'debug').
-
#connection_pressure_factors ⇒ Hash
readonly
Pressure response factors by pressure level.
-
#health_assessment_cache_duration ⇒ Integer
readonly
Cache duration in seconds (default: 30).
-
#max_batch_timeout_seconds ⇒ Integer
readonly
Maximum timeout in seconds (default: 120).
-
#max_concurrent_steps_limit ⇒ Integer
readonly
Maximum concurrent steps limit (default: 12).
-
#min_concurrent_steps ⇒ Integer
readonly
Minimum concurrent steps (default: 3).
Instance Method Summary collapse
-
#calculate_batch_timeout(batch_size) ⇒ Integer
Calculate batch timeout for a given batch size.
-
#future_cleanup_wait_seconds ⇒ Integer
Future cleanup wait time.
-
#gc_trigger_batch_size_threshold ⇒ Integer
GC trigger batch size threshold.
-
#gc_trigger_duration_threshold ⇒ Integer
GC trigger duration threshold.
-
#should_trigger_gc?(batch_size, batch_duration) ⇒ Boolean
Check if batch should trigger garbage collection.
-
#validate! ⇒ Boolean
Comprehensive validation.
-
#validate_concurrency_bounds ⇒ Array<String>
Validate concurrency bounds.
-
#validate_connection_configuration ⇒ Array<String>
Validate connection configuration.
-
#validate_timeout_configuration ⇒ Array<String>
Validate timeout configuration.
Methods inherited from BaseConfig
Constructor Details
This class inherits a constructor from Tasker::Types::BaseConfig
Instance Attribute Details
#batch_timeout_base_seconds ⇒ Integer (readonly)
Returns Base timeout in seconds (default: 30).
78 |
# File 'lib/tasker/types/execution_config.rb', line 78 attribute :batch_timeout_base_seconds, Types::Integer.default(30) |
#batch_timeout_per_step_seconds ⇒ Integer (readonly)
Returns Per-step timeout in seconds (default: 5).
87 |
# File 'lib/tasker/types/execution_config.rb', line 87 attribute :batch_timeout_per_step_seconds, Types::Integer.default(5) |
#concurrency_cache_duration ⇒ Integer (readonly)
Returns Cache duration in seconds (default: 30).
69 |
# File 'lib/tasker/types/execution_config.rb', line 69 attribute :concurrency_cache_duration, Types::Integer.default(30) |
#connection_health_log_level ⇒ String (readonly)
Returns Log level (default: 'debug').
131 |
# File 'lib/tasker/types/execution_config.rb', line 131 attribute :connection_health_log_level, Types::String.default('debug') |
#connection_pressure_factors ⇒ Hash (readonly)
Returns Pressure response factors by pressure level.
106 107 108 109 110 111 112 113 |
# File 'lib/tasker/types/execution_config.rb', line 106 attribute :connection_pressure_factors, Types::Hash.default(proc { { low: 0.8, # Use 80% of available when pressure is low moderate: 0.6, # Use 60% of available when pressure is moderate high: 0.4, # Use 40% of available when pressure is high critical: 0.2 # Use 20% of available when pressure is critical } }.freeze) |
#health_assessment_cache_duration ⇒ Integer (readonly)
Returns Cache duration in seconds (default: 30).
122 |
# File 'lib/tasker/types/execution_config.rb', line 122 attribute :health_assessment_cache_duration, Types::Integer.default(30) |
#max_batch_timeout_seconds ⇒ Integer (readonly)
Returns Maximum timeout in seconds (default: 120).
96 |
# File 'lib/tasker/types/execution_config.rb', line 96 attribute :max_batch_timeout_seconds, Types::Integer.default(120) |
#max_concurrent_steps_limit ⇒ Integer (readonly)
Returns Maximum concurrent steps limit (default: 12).
60 |
# File 'lib/tasker/types/execution_config.rb', line 60 attribute :max_concurrent_steps_limit, Types::Integer.default(12) |
#min_concurrent_steps ⇒ Integer (readonly)
Returns Minimum concurrent steps (default: 3).
50 |
# File 'lib/tasker/types/execution_config.rb', line 50 attribute :min_concurrent_steps, Types::Integer.default(3) |
Instance Method Details
#calculate_batch_timeout(batch_size) ⇒ Integer
Calculate batch timeout for a given batch size
181 182 183 184 |
# File 'lib/tasker/types/execution_config.rb', line 181 def calculate_batch_timeout(batch_size) calculated_timeout = batch_timeout_base_seconds + (batch_size * batch_timeout_per_step_seconds) [calculated_timeout, max_batch_timeout_seconds].min end |
#future_cleanup_wait_seconds ⇒ Integer
Future cleanup wait time
Time to wait for executing futures during cleanup. Based on Ruby Concurrent::Future characteristics - 1 second is optimal for most Ruby applications and provides good balance of responsiveness vs resource cleanup.
147 148 149 |
# File 'lib/tasker/types/execution_config.rb', line 147 def future_cleanup_wait_seconds 1 end |
#gc_trigger_batch_size_threshold ⇒ Integer
GC trigger batch size threshold
Batch size that triggers intelligent garbage collection. Based on Ruby memory management patterns - 6 concurrent operations is typically where memory pressure becomes noticeable in Ruby.
158 159 160 |
# File 'lib/tasker/types/execution_config.rb', line 158 def gc_trigger_batch_size_threshold 6 end |
#gc_trigger_duration_threshold ⇒ Integer
GC trigger duration threshold
Batch duration that triggers intelligent garbage collection. Based on Ruby GC timing characteristics - 30 seconds is typically when Ruby benefits from explicit GC triggering.
169 170 171 |
# File 'lib/tasker/types/execution_config.rb', line 169 def gc_trigger_duration_threshold 30 end |
#should_trigger_gc?(batch_size, batch_duration) ⇒ Boolean
Check if batch should trigger garbage collection
191 192 193 194 |
# File 'lib/tasker/types/execution_config.rb', line 191 def should_trigger_gc?(batch_size, batch_duration) batch_size >= gc_trigger_batch_size_threshold || batch_duration >= gc_trigger_duration_threshold end |
#validate! ⇒ Boolean
Comprehensive validation
rubocop:disable Naming/PredicateMethod
279 280 281 282 283 284 285 |
# File 'lib/tasker/types/execution_config.rb', line 279 def validate! errors = validate_concurrency_bounds + validate_timeout_configuration + validate_connection_configuration raise Dry::Struct::Error, "ExecutionConfig validation failed: #{errors.join(', ')}" unless errors.empty? true end |
#validate_concurrency_bounds ⇒ Array<String>
Validate concurrency bounds
Ensures min <= max and both are positive
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/tasker/types/execution_config.rb', line 200 def validate_concurrency_bounds errors = [] errors << "min_concurrent_steps must be positive (got: #{min_concurrent_steps})" if min_concurrent_steps <= 0 if max_concurrent_steps_limit <= 0 errors << "max_concurrent_steps_limit must be positive (got: #{max_concurrent_steps_limit})" end if min_concurrent_steps > max_concurrent_steps_limit errors << "min_concurrent_steps (#{min_concurrent_steps}) cannot exceed " \ "max_concurrent_steps_limit (#{max_concurrent_steps_limit})" end errors end |
#validate_connection_configuration ⇒ Array<String>
Validate connection configuration
Ensures connection pressure factors and health settings are valid
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/tasker/types/execution_config.rb', line 244 def validate_connection_configuration errors = [] if health_assessment_cache_duration <= 0 errors << "health_assessment_cache_duration must be positive (got: #{health_assessment_cache_duration})" end # Validate connection pressure factors required_pressure_levels = %i[low moderate high critical] missing_levels = required_pressure_levels - connection_pressure_factors.keys unless missing_levels.empty? errors << "connection_pressure_factors missing required levels: #{missing_levels.join(', ')}" end connection_pressure_factors.each do |level, factor| unless factor.is_a?(Numeric) && factor >= 0.0 && factor <= 1.0 errors << "connection_pressure_factors[#{level}] must be between 0.0 and 1.0 (got: #{factor})" end end # Validate log level valid_log_levels = %w[debug info warn error fatal] unless valid_log_levels.include?(connection_health_log_level) errors << "connection_health_log_level must be one of: #{valid_log_levels.join(', ')} " \ "(got: #{connection_health_log_level})" end errors end |
#validate_timeout_configuration ⇒ Array<String>
Validate timeout configuration
Ensures timeouts are positive and logical
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/tasker/types/execution_config.rb', line 221 def validate_timeout_configuration errors = [] if batch_timeout_base_seconds <= 0 errors << "batch_timeout_base_seconds must be positive (got: #{batch_timeout_base_seconds})" end if batch_timeout_per_step_seconds <= 0 errors << "batch_timeout_per_step_seconds must be positive (got: #{batch_timeout_per_step_seconds})" end if max_batch_timeout_seconds <= batch_timeout_base_seconds errors << "max_batch_timeout_seconds (#{max_batch_timeout_seconds}) must be greater than " \ "batch_timeout_base_seconds (#{batch_timeout_base_seconds})" end errors end |