Class: Tasker::Orchestration::TaskFinalizer::DelayCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/tasker/orchestration/task_finalizer.rb

Overview

Service class to calculate delays Reduces complexity by organizing delay calculation logic

Class Method Summary collapse

Class Method Details

.backoff_configTasker::Types::BackoffConfig

Get backoff configuration with memoization

Returns:



442
443
444
# File 'lib/tasker/orchestration/task_finalizer.rb', line 442

def backoff_config
  @backoff_config ||= Tasker::Configuration.configuration.backoff
end

.calculate_reenqueue_delay(context) ⇒ Integer

Calculate intelligent re-enqueue delay based on execution context and step backoff timing

This method considers the actual backoff timing of failed steps to avoid reenqueuing tasks before any steps are ready for retry.

Parameters:

Returns:

  • (Integer)

    Delay in seconds



473
474
475
476
477
478
479
480
481
482
483
# File 'lib/tasker/orchestration/task_finalizer.rb', line 473

def calculate_reenqueue_delay(context)
  return default_delay unless context

  # For waiting_for_dependencies status, check if we have failed steps with backoff timing
  if context.execution_status == Constants::TaskExecution::ExecutionStatus::WAITING_FOR_DEPENDENCIES
    optimal_delay = calculate_optimal_backoff_delay(context.task_id)
    return optimal_delay if optimal_delay.positive?
  end

  delay_map.fetch(context.execution_status, default_delay)
end

.default_delayObject

Default delay for unclear states or no context



457
458
459
# File 'lib/tasker/orchestration/task_finalizer.rb', line 457

def default_delay
  backoff_config.default_reenqueue_delay
end

.delay_mapObject

Frozen hash for O(1) delay lookups with descriptive comments Values now use configurable backoff progression



448
449
450
451
452
453
454
# File 'lib/tasker/orchestration/task_finalizer.rb', line 448

def delay_map
  @delay_map ||= {
    Constants::TaskExecution::ExecutionStatus::HAS_READY_STEPS => backoff_config.reenqueue_delays[:has_ready_steps],
    Constants::TaskExecution::ExecutionStatus::WAITING_FOR_DEPENDENCIES => backoff_config.reenqueue_delays[:waiting_for_dependencies],
    Constants::TaskExecution::ExecutionStatus::PROCESSING => backoff_config.reenqueue_delays[:processing]
  }.freeze
end

.maximum_delayObject

Maximum delay cap



462
463
464
# File 'lib/tasker/orchestration/task_finalizer.rb', line 462

def maximum_delay
  backoff_config.max_backoff_seconds
end