class OkComputer::AlgoliaCheck

Constants

STATUS_URL
StatusFailed

Attributes

api_key[RW]
app_id[RW]

Public Class Methods

new(url: STATUS_URL, app_id: nil, api_key: nil, request_timeout: 5) click to toggle source
Calls superclass method
# File lib/ok_computer/checks/algolia_check.rb, line 14
def initialize(url: STATUS_URL, app_id: nil, api_key: nil, request_timeout: 5)
  super(url, request_timeout)

  self.app_id = app_id.presence
  self.api_key = api_key.presence
end

Public Instance Methods

check() click to toggle source

Public: Return the status of the Monitoring check

# File lib/ok_computer/checks/algolia_check.rb, line 22
def check
  status, body = perform_request
  raise(StatusFailed, body) unless status == 200 && body['status'].values.all? { |v| v == 'operational' }

  mark_message('Monitoring check successful')
rescue StandardError => e
  mark_message("Error: '#{e}'")
  mark_failure
end
perform_request() click to toggle source
# File lib/ok_computer/checks/algolia_check.rb, line 32
def perform_request
  response = Faraday.get(url, request: { timeout: request_timeout }) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.headers['X-Algolia-API-Key'] = api_key
    req.headers['X-Algolia-Application-Id'] = app_id
  end

  [response.status, MultiJson.decode(response.body)]
rescue StandardError => e
  raise(StatusFailed, e)
end