Class: Tasker::Types::ExecutionConfig

Inherits:
BaseConfig
  • Object
show all
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

Examples:

Basic usage

config = ExecutionConfig.new(
  max_concurrent_steps_limit: 20,  # High-performance system
  batch_timeout_base_seconds: 60   # API-heavy workflows
)

Environment-specific tuning

# Development environment
config = ExecutionConfig.new(
  min_concurrent_steps: 2,
  max_concurrent_steps_limit: 6,
  concurrency_cache_duration: 60
)

# Production environment
config = ExecutionConfig.new(
  min_concurrent_steps: 5,
  max_concurrent_steps_limit: 25,
  batch_timeout_base_seconds: 45,
  max_batch_timeout_seconds: 300
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseConfig

#initialize

Constructor Details

This class inherits a constructor from Tasker::Types::BaseConfig

Instance Attribute Details

#batch_timeout_base_secondsInteger (readonly)

Returns Base timeout in seconds (default: 30).

Returns:

  • (Integer)

    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_secondsInteger (readonly)

Returns Per-step timeout in seconds (default: 5).

Returns:

  • (Integer)

    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_durationInteger (readonly)

Returns Cache duration in seconds (default: 30).

Returns:

  • (Integer)

    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_levelString (readonly)

Returns Log level (default: 'debug').

Returns:

  • (String)

    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_factorsHash (readonly)

Returns Pressure response factors by pressure level.

Returns:

  • (Hash)

    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_durationInteger (readonly)

Returns Cache duration in seconds (default: 30).

Returns:

  • (Integer)

    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_secondsInteger (readonly)

Returns Maximum timeout in seconds (default: 120).

Returns:

  • (Integer)

    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_limitInteger (readonly)

Returns Maximum concurrent steps limit (default: 12).

Returns:

  • (Integer)

    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_stepsInteger (readonly)

Returns Minimum concurrent steps (default: 3).

Returns:

  • (Integer)

    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

Parameters:

  • batch_size (Integer)

    Number of steps in the batch

Returns:

  • (Integer)

    Calculated timeout in seconds



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_secondsInteger

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.

Returns:

  • (Integer)

    Wait time in seconds



147
148
149
# File 'lib/tasker/types/execution_config.rb', line 147

def future_cleanup_wait_seconds
  1
end

#gc_trigger_batch_size_thresholdInteger

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.

Returns:

  • (Integer)

    Batch size threshold



158
159
160
# File 'lib/tasker/types/execution_config.rb', line 158

def gc_trigger_batch_size_threshold
  6
end

#gc_trigger_duration_thresholdInteger

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.

Returns:

  • (Integer)

    Duration threshold in seconds



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

Parameters:

  • batch_size (Integer)

    Size of the batch

  • batch_duration (Float)

    Duration of batch execution in seconds

Returns:

  • (Boolean)

    Whether to trigger GC



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

Returns:

  • (Boolean)

    True if valid, raises exception if invalid

Raises:

  • (Dry::Struct::Error)

    If validation fails



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_boundsArray<String>

Validate concurrency bounds

Ensures min <= max and both are positive

Returns:

  • (Array<String>)

    Validation errors (empty if valid)



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_configurationArray<String>

Validate connection configuration

Ensures connection pressure factors and health settings are valid

Returns:

  • (Array<String>)

    Validation errors (empty if 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_configurationArray<String>

Validate timeout configuration

Ensures timeouts are positive and logical

Returns:

  • (Array<String>)

    Validation errors (empty if valid)



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