Class: OpenAICompatibleErrors::RetryPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/openai_compatible_errors/retry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:, reason:, delay_ms: nil, delay_source: nil) ⇒ RetryPlan

Returns a new instance of RetryPlan.



86
87
88
89
90
91
92
93
94
95
# File 'lib/openai_compatible_errors/retry.rb', line 86

def initialize(action:, reason:, delay_ms: nil, delay_source: nil)
  action_symbol = action.is_a?(Symbol) || action.is_a?(String) ? action.to_sym : nil
  reason_symbol = reason.is_a?(Symbol) || reason.is_a?(String) ? reason.to_sym : nil
  @action = RETRY_ACTIONS.include?(action_symbol) ? action_symbol : :manual_decision
  @reason = RETRY_REASONS.include?(reason_symbol) ? reason_symbol : :invalid_context
  @delay_ms = delay_ms.is_a?(Integer) && delay_ms >= 0 ? delay_ms : nil
  source_symbol = delay_source.is_a?(Symbol) || delay_source.is_a?(String) ? delay_source.to_sym : nil
  @delay_source = DELAY_SOURCES.include?(source_symbol) ? source_symbol : nil
  freeze
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



84
85
86
# File 'lib/openai_compatible_errors/retry.rb', line 84

def action
  @action
end

#delay_msObject (readonly)

Returns the value of attribute delay_ms.



84
85
86
# File 'lib/openai_compatible_errors/retry.rb', line 84

def delay_ms
  @delay_ms
end

#delay_sourceObject (readonly)

Returns the value of attribute delay_source.



84
85
86
# File 'lib/openai_compatible_errors/retry.rb', line 84

def delay_source
  @delay_source
end

#reasonObject (readonly)

Returns the value of attribute reason.



84
85
86
# File 'lib/openai_compatible_errors/retry.rb', line 84

def reason
  @reason
end

Instance Method Details

#do_not_retry?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/openai_compatible_errors/retry.rb', line 101

def do_not_retry?
  @action == :do_not_retry
end

#manual_decision?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/openai_compatible_errors/retry.rb', line 105

def manual_decision?
  @action == :manual_decision
end

#retry?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/openai_compatible_errors/retry.rb', line 97

def retry?
  @action == :retry
end

#to_hObject



109
110
111
112
# File 'lib/openai_compatible_errors/retry.rb', line 109

def to_h
  { action: @action, reason: @reason, delay_ms: @delay_ms,
    delay_source: @delay_source }.compact.freeze
end