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.



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

def initialize
  @attempts = []
  @result = nil
  @last_response = nil
  @entry_resolution = nil
  @resolution_tried = false
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



27
28
29
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 27

def attempts
  @attempts
end

#entry_resolutionObject (readonly)

Returns the value of attribute entry_resolution.



27
28
29
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 27

def entry_resolution
  @entry_resolution
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



27
28
29
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 27

def last_response
  @last_response
end

#resultObject (readonly)

Returns the value of attribute result.



27
28
29
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 27

def result
  @result
end

Instance Method Details

#mark_resolution_tried!void

This method returns an undefined value.



44
45
46
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 44

def mark_resolution_tried!
  @resolution_tried = true
end

#record_error(strategy:, error:) ⇒ void

This method returns an undefined value.

Parameters:

  • strategy (Symbol)

    strategy that raised

  • error (Exception)

    caught error



57
58
59
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 57

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



65
66
67
68
69
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 65

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

#remember_entry_resolution(result) ⇒ void

This method returns an undefined value.

Parameters:



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

def remember_entry_resolution(result)
  @entry_resolution = FeedResolution::Diag.from_result(result)
end

#remember_response(response) ⇒ void

This method returns an undefined value.

Parameters:



73
74
75
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 73

def remember_response(response)
  @last_response = response
end

#resolution_tried?Boolean

Returns whether entry resolution already ran for this chain.

Returns:

  • (Boolean)

    whether entry resolution already ran for this chain



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

def resolution_tried? = @resolution_tried

#succeed!(response:, articles:, dedup_dropped:, selected_strategy:, attempt_count:, scrape_target:, admission_drops: {}) ⇒ void

This method returns an undefined value.

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength -- PipelineOutcome kwargs stay co-located

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

  • admission_drops (Hash{String => Integer}) (defaults to: {})

    Cleanup drop tallies

  • scrape_target (Html2rss::ScrapeTarget)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 86

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

#succeeded?Boolean

Returns true when a strategy already yielded items.

Returns:

  • (Boolean)

    true when a strategy already yielded items



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

def succeeded? = !result.nil?