Class: OkComputer::AlgoliaCheck
- Inherits:
-
HttpCheck
- Object
- HttpCheck
- OkComputer::AlgoliaCheck
- Defined in:
- lib/ok_computer/checks/algolia_check.rb
Constant Summary collapse
- StatusFailed =
Class.new(StandardError)
- STATUS_URL =
"https://status.algolia.com/1/status"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
Instance Method Summary collapse
-
#check ⇒ Object
Public: Return the status of the Monitoring check.
-
#initialize(url: STATUS_URL, app_id: nil, api_key: nil, request_timeout: 5) ⇒ AlgoliaCheck
constructor
A new instance of AlgoliaCheck.
- #perform_request ⇒ Object
Constructor Details
#initialize(url: STATUS_URL, app_id: nil, api_key: nil, request_timeout: 5) ⇒ AlgoliaCheck
Returns a new instance of AlgoliaCheck.
14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/ok_computer/checks/algolia_check.rb', line 12 def api_key @api_key end |
#app_id ⇒ Object
Returns the value of attribute app_id.
12 13 14 |
# File 'lib/ok_computer/checks/algolia_check.rb', line 12 def app_id @app_id end |
Instance Method Details
#check ⇒ Object
Public: Return the status of the Monitoring check
22 23 24 25 26 27 28 29 30 |
# 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?("operational") ("Monitoring check successful") rescue StandardError => e ("Error: '#{e}'") mark_failure end |
#perform_request ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# 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 |