Method: HealthCheck::Utils.process_checks

Defined in:
lib/health_check/utils.rb

.process_checks(checks) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/health_check/utils.rb', line 21

def self.process_checks(checks)
  errors = ''
  checks.split('_').each do |check|
    case check
      when 'and', 'site'
        # do nothing
      when "database"
        HealthCheck::Utils.get_database_version
      when "email"
        errors << HealthCheck::Utils.check_email
      when "migrations", "migration"
        if defined?(ActiveRecord::Migration) and ActiveRecord::Migration.respond_to?(:check_pending!)
          # Rails 4+
          begin
            ActiveRecord::Migration.check_pending!
          rescue ActiveRecord::PendingMigrationError => ex
              errors << ex.message
          end
        else
          database_version  = HealthCheck::Utils.get_database_version
          migration_version = HealthCheck::Utils.get_migration_version
          if database_version.to_i != migration_version.to_i
            errors << "Current database version (#{database_version}) does not match latest migration (#{migration_version}). "
          end
        end
      when 'cache'
        errors << HealthCheck::Utils.check_cache
      when "standard"
        errors << HealthCheck::Utils.process_checks(HealthCheck.standard_checks.join('_'))
        errors << HealthCheck::Utils.process_checks("email") if HealthCheck::Utils.mailer_configured?
      when "custom"
        HealthCheck.custom_checks.each do |custom_check|
          errors << custom_check.call(self)
        end
      when "all", "full"
        errors << HealthCheck::Utils.process_checks(HealthCheck.full_checks.join('_'))
      else
        return "invalid argument to health_test. "
    end
  end
  return errors
end