Class: Html2rss::FeedPipeline::AutoFallback::AttemptState

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/feed_pipeline/auto_fallback.rb

Overview

Mutable run state for one auto-fallback chain: attempts plus selected result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttemptState

Returns a new instance of AttemptState.



31
32
33
34
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 31

def initialize
  @attempts = []
  @result = nil
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



29
30
31
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 29

def attempts
  @attempts
end

#resultObject (readonly)

Returns the value of attribute result.



29
30
31
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 29

def result
  @result
end

Instance Method Details

#record_error(strategy:, error:) ⇒ void

This method returns an undefined value.

Parameters:

  • strategy (Symbol)

    strategy that raised

  • error (Exception)

    caught error



42
43
44
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 42

def record_error(strategy:, error:)
  @attempts << { strategy:, items_count: nil, error_class: error.class.name }
end

#record_items(strategy:, items_count:, transport_meta: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • strategy (Symbol)

    strategy that returned a response

  • items_count (Integer)

    extracted article count

  • transport_meta (Hash, nil) (defaults to: nil)

    optional allowlisted upstream telemetry



50
51
52
53
54
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 50

def record_items(strategy:, items_count:, transport_meta: nil)
  attempt = { strategy:, items_count:, error_class: nil }
  attempt[:transport_meta] = transport_meta if transport_meta && !transport_meta.empty?
  @attempts << attempt
end

#succeed!(response:, articles:, dedup_dropped:, selected_strategy:, attempt_count:) ⇒ void

This method returns an undefined value.

Parameters:

  • response (RequestService::Response)

    successful response

  • articles (Array)

    extracted articles

  • dedup_dropped (Integer)

    articles removed by deduplication

  • selected_strategy (Symbol)

    concrete strategy that produced items

  • attempt_count (Integer)

    number of attempts recorded for this chain



62
63
64
65
66
67
68
69
70
71
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 62

def succeed!(response:, articles:, dedup_dropped:, selected_strategy:, attempt_count:)
  @result = PipelineOutcome.new(
    response:,
    articles:,
    dedup_dropped:,
    selected_strategy:,
    attempt_count:,
    strategy_attempts: attempts
  )
end

#succeeded?Boolean

Returns true when a strategy already yielded items.

Returns:

  • (Boolean)

    true when a strategy already yielded items



37
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 37

def succeeded? = !result.nil?