Class: SourceMonitor::Fetching::FeedFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/source_monitor/fetching/feed_fetcher.rb,
lib/source_monitor/fetching/feed_fetcher/source_updater.rb,
lib/source_monitor/fetching/feed_fetcher/entry_processor.rb,
lib/source_monitor/fetching/feed_fetcher/failure_outcome.rb,
lib/source_monitor/fetching/feed_fetcher/success_outcome.rb,
lib/source_monitor/fetching/feed_fetcher/adaptive_interval.rb

Defined Under Namespace

Classes: AdaptiveInterval, EntryProcessingResult, EntryProcessor, FailureOutcome, ResponseWrapper, Result, SourceUpdater, SuccessOutcome

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, client: nil, jitter: nil) ⇒ FeedFetcher

Returns a new instance of FeedFetcher.



47
48
49
50
51
# File 'lib/source_monitor/fetching/feed_fetcher.rb', line 47

def initialize(source:, client: nil, jitter: nil)
  @source = source
  @client = client
  @jitter_proc = jitter
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



45
46
47
# File 'lib/source_monitor/fetching/feed_fetcher.rb', line 45

def client
  @client
end

#jitter_procObject (readonly)

Returns the value of attribute jitter_proc.



45
46
47
# File 'lib/source_monitor/fetching/feed_fetcher.rb', line 45

def jitter_proc
  @jitter_proc
end

#sourceObject (readonly)

Returns the value of attribute source.



45
46
47
# File 'lib/source_monitor/fetching/feed_fetcher.rb', line 45

def source
  @source
end

Instance Method Details

#callObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/source_monitor/fetching/feed_fetcher.rb', line 53

def call
  attempt_started_at = Time.current
  instrumentation_payload = base_instrumentation_payload
  started_monotonic = SourceMonitor::Instrumentation.monotonic_time
  result = nil

  SourceMonitor::Instrumentation.fetch_start(instrumentation_payload)

  result = perform_fetch(attempt_started_at, instrumentation_payload)
rescue FetchError => error
  result = handle_failure(error, started_at: attempt_started_at, instrumentation_payload:)
rescue StandardError => error
  fetch_error = UnexpectedResponseError.new(error.message, original_error: error)
  result = handle_failure(fetch_error, started_at: attempt_started_at, instrumentation_payload:)
ensure
  instrumentation_payload[:duration_ms] ||= duration_since(started_monotonic)
  SourceMonitor::Instrumentation.fetch_finish(instrumentation_payload)
  return result
end