Module: Heartcheck

Defined in:
lib/heartcheck/app.rb,
lib/heartcheck.rb,
lib/heartcheck/logger.rb,
lib/heartcheck/version.rb,
lib/heartcheck/caching_app.rb,
lib/heartcheck/checks/base.rb,
lib/heartcheck/checks/process.rb,
lib/heartcheck/errors/warning.rb,
lib/heartcheck/executors/base.rb,
lib/heartcheck/checks/firewall.rb,
lib/heartcheck/controllers/dev.rb,
lib/heartcheck/controllers/base.rb,
lib/heartcheck/controllers/info.rb,
lib/heartcheck/caching_app/cache.rb,
lib/heartcheck/checks/watch_file.rb,
lib/heartcheck/services/firewall.rb,
lib/heartcheck/executors/threaded.rb,
lib/heartcheck/controllers/inspect.rb,
lib/heartcheck/errors/routing_error.rb,
lib/heartcheck/generators/generator.rb,
lib/heartcheck/controllers/essential.rb,
lib/heartcheck/controllers/functional.rb,
lib/heartcheck/controllers/environment.rb,
lib/heartcheck/controllers/health_check.rb

Overview

A rack middleware to wrap around App in a cache Mount an instance of this class passing an app or use this in Rack. This accepts an optional ttl for the cache that defaults to 300 seconds.

Defined Under Namespace

Modules: Checks, Controllers, Errors, Executors, Services Classes: App, CachingApp, Generator, Logger

Constant Summary collapse

VERSION =
'2.0.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.checksObject



14
15
16
# File 'lib/heartcheck.rb', line 14

def checks
  @checks
end

.executorHeartcheck::Executors::Base

an executor class that respond to dispatch(checkers)



17
18
19
# File 'lib/heartcheck.rb', line 17

def executor
  @executor
end

.loggerObject

Is used to log some messages when checking if the logger is not set it's returns de default_logger.

Returns:

  • (Object)

    the logger object



26
27
28
# File 'lib/heartcheck.rb', line 26

def logger
  @logger ||= default_logger
end

Class Method Details

.add(name, options = {}) { ... } ⇒ void

This method returns an undefined value.

It's used to add an instance of a check to the check list

Examples:

Heartcheck.add(:base) do |c|
  c.name = 'Base check'
end

Parameters:

  • name (String)

    to identify in the result page

  • options (Hash) (defaults to: {})

    the options to create an instance of a check.

Options Hash (options):

  • :class (String)

    The class name to get an instance

Yields:

  • a block to config the instance



59
60
61
62
63
64
65
66
67
68
# File 'lib/heartcheck.rb', line 59

def add(name, options = {}, &block)
  class_name = options.fetch(:class) { constantize(name) }
  instance = Checks.const_get(class_name).new

  if block_given?
    checks << instance.tap(&block)
  else
    checks << instance
  end
end

.dev_checksArray<Check>

filter checks that are not functional

Returns:

  • (Array<Check>)

    checks that are not functional



87
88
89
# File 'lib/heartcheck.rb', line 87

def dev_checks
  checks.select { |ctx| !ctx.functional? }
end

.essential_checksArray<Check>

filter checks that are essential

Returns:

  • (Array<Check>)

    checks that are essential



73
74
75
# File 'lib/heartcheck.rb', line 73

def essential_checks
  checks.select { |ctx| !ctx.functional? && !ctx.dev? }
end

.functional_checksArray<Check>

filter checks that are functional

Returns:

  • (Array<Check>)

    checks that are functional



80
81
82
# File 'lib/heartcheck.rb', line 80

def functional_checks
  checks.select(&:functional?)
end

.info_checksArray<Check>

filter checks that has some information

Returns:

  • (Array<Check>)

    checks that respond to :info



94
95
96
# File 'lib/heartcheck.rb', line 94

def info_checks
  checks.select { |ctx| ctx.respond_to?(:info) }
end

.setup { ... } ⇒ void

This method is abstract.

This method returns an undefined value.

Is used to configure.

Examples:

Heartcheck.setup do |c|
  puts c
end

Yields:

  • A bock that recieve the class



41
42
43
# File 'lib/heartcheck.rb', line 41

def setup
  yield(self)
end

.use_threaded_executor!Heartcheck::Executors::Threaded

change current executor to a threaded implementation requires 'concurrent-ruby'



109
110
111
112
113
114
# File 'lib/heartcheck.rb', line 109

def use_threaded_executor!
  require "concurrent"
  require "heartcheck/executors/threaded"

  self.executor = Heartcheck::Executors::Threaded.new
end