rails-healthcheck 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/healthcheck.rb +29 -0
- data/lib/healthcheck/check.rb +16 -0
- data/lib/healthcheck/checker.rb +27 -0
- data/lib/healthcheck/configuration.rb +22 -0
- data/lib/healthcheck/engine.rb +8 -0
- data/lib/healthcheck/error.rb +13 -0
- data/lib/healthcheck/railtie.rb +12 -0
- data/lib/healthcheck/router.rb +9 -0
- data/lib/healthcheck/tasks/setup.rake +66 -0
- data/lib/healthcheck/version.rb +5 -0
- data/lib/rails-healthcheck.rb +3 -0
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0101c38ef564e878ce55f0aaea701606c624fd2f7c7bb35d1b5c40d814dccf1b
|
4
|
+
data.tar.gz: baf68a65097dfaae941df75caa1a263b7e7a2c27bb8f32f818a62af95c4f85f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae53712ee12b40e78121ebf6de7d9d36b278d8c5b57472e046354b247c92bafbfe69966e691b4b2ae712034da84d223742d85498587cb81b6c342c9ce1ea5f70
|
7
|
+
data.tar.gz: a6237e5a946d94fc3ad885fdc963b89db21b124260e3c5544594736856893130d5f31165e748a2d585c5f6115b0fae1b5c5897d3a9f847423e73fe2725ad58aa
|
data/lib/healthcheck.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'healthcheck/version'
|
4
|
+
require 'healthcheck/configuration'
|
5
|
+
require 'healthcheck/check'
|
6
|
+
require 'healthcheck/checker'
|
7
|
+
require 'healthcheck/error'
|
8
|
+
require 'healthcheck/router'
|
9
|
+
require 'healthcheck/engine'
|
10
|
+
|
11
|
+
module Healthcheck
|
12
|
+
require 'healthcheck/railtie' if defined?(Rails)
|
13
|
+
|
14
|
+
Configuration::SETTINGS.each do |setting|
|
15
|
+
send(:define_singleton_method, setting, -> { configuration.send(setting) })
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.routes(router)
|
27
|
+
Healthcheck::Router.mount(router)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Healthcheck
|
4
|
+
class Checker
|
5
|
+
attr_accessor :errors
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@errors = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def check
|
12
|
+
Healthcheck.checks.map { |c| Thread.new { execute(c) } }.each(&:join)
|
13
|
+
end
|
14
|
+
|
15
|
+
def errored?
|
16
|
+
@errors.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def execute(check)
|
22
|
+
check.execute!
|
23
|
+
rescue StandardError => e
|
24
|
+
@errors << Error.new(check.name, e.class, e.message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Healthcheck
|
4
|
+
class Configuration
|
5
|
+
SETTINGS = %i[success error verbose route method checks].freeze
|
6
|
+
|
7
|
+
attr_accessor(*SETTINGS)
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
SETTINGS.each { |key, _| instance_variable_set("@#{key}", nil) }
|
11
|
+
clear!
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_check(name, block)
|
15
|
+
@checks << Check.new(name, block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear!
|
19
|
+
@checks = []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
INITIALIZER = 'config/initializers/healthcheck.rb'
|
6
|
+
OLD_ROUTES = 'config/routes.rb'
|
7
|
+
NEW_ROUTES = 'config/routes.rb.new'
|
8
|
+
ROUTES_SETUP = ' Healthcheck.routes(self)'
|
9
|
+
ROUTES_INIT = 'Rails.application.routes.draw do'
|
10
|
+
|
11
|
+
namespace :healthcheck do
|
12
|
+
desc 'Install the files and settings to the gem Healthcheck works'
|
13
|
+
task :install do
|
14
|
+
puts ' - invoke Rails::Healthcheck'
|
15
|
+
create_initializer
|
16
|
+
mount_route
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_initializer
|
21
|
+
FileUtils.mkdir_p(File.dirname(INITIALIZER))
|
22
|
+
File.open(INITIALIZER, 'w') { |file| file << settings }
|
23
|
+
puts ' - create config/initializers/healthcheck.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
def mount_route
|
27
|
+
return unless File.exist?(OLD_ROUTES)
|
28
|
+
|
29
|
+
puts ' - modify config/routes.rb'
|
30
|
+
File.open(NEW_ROUTES, 'w') do |new_routes|
|
31
|
+
File.foreach(OLD_ROUTES) do |line|
|
32
|
+
new_routes.puts(line)
|
33
|
+
if line.strip == ROUTES_INIT
|
34
|
+
new_routes.puts(ROUTES_SETUP)
|
35
|
+
new_routes.puts ''
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
File.delete(OLD_ROUTES)
|
41
|
+
File.rename(NEW_ROUTES, OLD_ROUTES)
|
42
|
+
end
|
43
|
+
|
44
|
+
def settings
|
45
|
+
<<~SETTINGS
|
46
|
+
# frozen_string_literal: true
|
47
|
+
|
48
|
+
Healthcheck.configure do |config|
|
49
|
+
config.success = 200
|
50
|
+
config.error = 503
|
51
|
+
config.verbose = false
|
52
|
+
config.route = '/healthcheck'
|
53
|
+
config.method = :get
|
54
|
+
|
55
|
+
# -- Checks --
|
56
|
+
# Check if the db is available
|
57
|
+
# config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
|
58
|
+
# Check if the db is available and without pending migrations
|
59
|
+
# config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
|
60
|
+
# Check if the cache is available
|
61
|
+
# config.add_check :cache, -> { Rails.cache.read('some_key') }
|
62
|
+
# Check if the application required envs are defined
|
63
|
+
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
|
64
|
+
end
|
65
|
+
SETTINGS
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-healthcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- linqueta
|
@@ -131,6 +131,17 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- README.md
|
133
133
|
- app/controllers/healthcheck/healthchecks_controller.rb
|
134
|
+
- lib/healthcheck.rb
|
135
|
+
- lib/healthcheck/check.rb
|
136
|
+
- lib/healthcheck/checker.rb
|
137
|
+
- lib/healthcheck/configuration.rb
|
138
|
+
- lib/healthcheck/engine.rb
|
139
|
+
- lib/healthcheck/error.rb
|
140
|
+
- lib/healthcheck/railtie.rb
|
141
|
+
- lib/healthcheck/router.rb
|
142
|
+
- lib/healthcheck/tasks/setup.rake
|
143
|
+
- lib/healthcheck/version.rb
|
144
|
+
- lib/rails-healthcheck.rb
|
134
145
|
homepage: https://github.com/linqueta/rails-healthcheck
|
135
146
|
licenses:
|
136
147
|
- MIT
|