Class: Aidp::Harness::ErrorHandler::BackoffCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/harness/error_handler.rb

Overview

Helper classes

Instance Method Summary collapse

Instance Method Details

#calculate_delay(retry_count, strategy, base_delay, max_delay) ⇒ Object



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'lib/aidp/harness/error_handler.rb', line 592

def calculate_delay(retry_count, strategy, base_delay, max_delay)
  case strategy
  when :exponential
    delay = base_delay * (2**(retry_count - 1))
  when :linear
    delay = base_delay * retry_count
  when :fixed
    delay = base_delay
  when :none
    return 0.0
  else
    delay = base_delay
  end

  # Apply jitter if enabled
  if strategy != :none
    jitter = delay * 0.1 * (rand - 0.5) # ±10% jitter
    delay += jitter
  end

  # Cap at max delay
  [delay, max_delay].min
end