Class: Forem::HealthCheck

Inherits:
APIResource show all
Defined in:
lib/forem/resources/health_check.rb

Overview

Provides access to the health-check endpoints of a Forem instance.

Health checks let you verify that the various subsystems of a Forem deployment are operational. There are three separate checks: the application server, the database, and the cache layer.

Authentication

In production, the endpoints require an health-check-token header whose value matches the instance's Settings::General.health_check_token setting. The Forem controller bypasses the token check for requests originating from localhost, so a local-development instance accepts unauthenticated calls.

Pass the token via the token: keyword on each method (or on the service-level wrapper). The api-key header is not used by these endpoints — the token is a separate, dedicated mechanism.

Examples:

Production: pass the configured token

client.health_checks.app(token: ENV.fetch("FOREM_HEALTH_CHECK_TOKEN"))
#=> #<Forem::ForemObject {"message" => "App is up!"}>

Local-development Forem (token bypassed for localhost)

client.health_checks.app
#=> #<Forem::ForemObject {"message" => "App is up!"}>

See Also:

Constant Summary collapse

OBJECT_NAME =
"health_check"
RESOURCE_PATH =
"/api/health_checks"

Instance Attribute Summary

Attributes inherited from ForemObject

#requestor

Class Method Summary collapse

Methods inherited from APIResource

#refresh, resource_path, #resource_url

Methods inherited from ForemObject

#==, #[], #[]=, construct_from, cursor_list, #initialize, #inspect, #method_missing, paginated_list, #respond_to_missing?, #to_hash

Methods included from APIOperations::Request

included, #request

Constructor Details

This class inherits a constructor from Forem::ForemObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Forem::ForemObject

Class Method Details

.app(token: nil, **opts) ⇒ Forem::ForemObject

Application-server health.

Parameters:

  • token (String, nil) (defaults to: nil)

    value for the health-check-token header (required in production).

  • opts (Hash)

    per-request options

Returns:



38
39
40
# File 'lib/forem/resources/health_check.rb', line 38

def self.app(token: nil, **opts)
  check("/api/health_checks/app", token, opts)
end

.cache(token: nil, **opts) ⇒ Forem::ForemObject

Cache (Redis) connectivity & responsiveness.

Parameters:

  • token (String, nil) (defaults to: nil)

    value for the health-check-token header.

  • opts (Hash)

    per-request options

Returns:



54
55
56
# File 'lib/forem/resources/health_check.rb', line 54

def self.cache(token: nil, **opts)
  check("/api/health_checks/cache", token, opts)
end

.database(token: nil, **opts) ⇒ Forem::ForemObject

Database connectivity & responsiveness.

Parameters:

  • token (String, nil) (defaults to: nil)

    value for the health-check-token header.

  • opts (Hash)

    per-request options

Returns:



46
47
48
# File 'lib/forem/resources/health_check.rb', line 46

def self.database(token: nil, **opts)
  check("/api/health_checks/database", token, opts)
end