Class: SourceMonitor::Health::SourceHealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/source_monitor/health/source_health_check.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(source:, client: nil, now: Time.current) ⇒ SourceHealthCheck

Returns a new instance of SourceHealthCheck.



8
9
10
11
12
# File 'lib/source_monitor/health/source_health_check.rb', line 8

def initialize(source:, client: nil, now: Time.current)
  @source = source
  @client = client
  @now = now
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/source_monitor/health/source_health_check.rb', line 14

def call
  return Result.new(log: nil, success?: false, error: nil) unless source

  started_at = now
  response = nil
  error = nil

  begin
    response = connection.get(source.feed_url)
  rescue StandardError => exception
    error = exception
  end

  completed_at = Time.current
  log = create_log(response:, error:, started_at:, completed_at:)

  Result.new(log:, success?: log&.success?, error: error)
end