rails-healthcheck 1.0.4 → 1.0.5
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/README.md +1 -1
- data/app/controllers/healthcheck/healthchecks_controller.rb +7 -3
- data/lib/generators/healthcheck/install_generator.rb +31 -0
- data/lib/healthcheck/checker.rb +1 -1
- data/lib/healthcheck/router.rb +4 -1
- data/lib/healthcheck/version.rb +1 -1
- data/lib/healthcheck.rb +4 -8
- metadata +3 -4
- data/lib/healthcheck/railtie.rb +0 -12
- data/lib/healthcheck/tasks/setup.rake +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f365d0578746bf65bd75b360fbf3af46e3cba738a6eb9c9a3e88df133efee7c
|
4
|
+
data.tar.gz: e7c5d26b27e0f939a07e20a70f69dcac975ac9efc1d3ee06ec12d7a81f2f22dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d1d0412ade72f8d0a06d9ce2160164109e0d21bbe3c7cf13c1798267ecf59746581671602b552d6d023514e70c435c986749b15575844b328e2403f23ab0230
|
7
|
+
data.tar.gz: 400bee85de2479a5ae575a54c085c597fee2b46709c0cfa1066d628d17bf46d511a92563834ae0007613bad885130895555b38ea0d2df2c61e2db8aa4e113d72
|
data/README.md
CHANGED
@@ -23,13 +23,17 @@ module Healthcheck
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def success
|
26
|
-
head Healthcheck.success
|
26
|
+
head Healthcheck.configuration.success
|
27
27
|
end
|
28
28
|
|
29
29
|
def error
|
30
|
-
return head(Healthcheck.error) unless Healthcheck.verbose
|
30
|
+
return head(Healthcheck.configuration.error) unless Healthcheck.configuration.verbose
|
31
31
|
|
32
|
-
render json: {
|
32
|
+
render json: {
|
33
|
+
code: Healthcheck.configuration.error,
|
34
|
+
errors: checker.errors.as_json
|
35
|
+
},
|
36
|
+
status: Healthcheck.configuration.error
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module Healthcheck
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
def create_initializer_file
|
8
|
+
create_file(
|
9
|
+
'config/initializers/healthcheck.rb',
|
10
|
+
<<~HEALTHCHECK_INITIALIZER_TEXT
|
11
|
+
# frozen_string_literal: true
|
12
|
+
|
13
|
+
Healthcheck.configure do |config|
|
14
|
+
config.success = 200
|
15
|
+
config.error = 503
|
16
|
+
config.verbose = false
|
17
|
+
config.route = '/healthcheck'
|
18
|
+
config.method = :get
|
19
|
+
|
20
|
+
# -- Checks --
|
21
|
+
# config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
|
22
|
+
# config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
|
23
|
+
# config.add_check :cache, -> { Rails.cache.read('some_key') }
|
24
|
+
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
|
25
|
+
end
|
26
|
+
HEALTHCHECK_INITIALIZER_TEXT
|
27
|
+
)
|
28
|
+
route 'Healthcheck.routes(self)'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/healthcheck/checker.rb
CHANGED
data/lib/healthcheck/router.rb
CHANGED
@@ -3,7 +3,10 @@
|
|
3
3
|
module Healthcheck
|
4
4
|
class Router
|
5
5
|
def self.mount(router)
|
6
|
-
router.send(
|
6
|
+
router.send(
|
7
|
+
Healthcheck.configuration.method,
|
8
|
+
Healthcheck.configuration.route => 'healthcheck/healthchecks#check'
|
9
|
+
)
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
data/lib/healthcheck/version.rb
CHANGED
data/lib/healthcheck.rb
CHANGED
@@ -9,21 +9,17 @@ require 'healthcheck/router'
|
|
9
9
|
require 'healthcheck/engine'
|
10
10
|
|
11
11
|
module Healthcheck
|
12
|
-
|
12
|
+
module_function
|
13
13
|
|
14
|
-
|
15
|
-
send(:define_singleton_method, setting, -> { configuration.send(setting) })
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.configure
|
14
|
+
def configure
|
19
15
|
yield(configuration)
|
20
16
|
end
|
21
17
|
|
22
|
-
def
|
18
|
+
def configuration
|
23
19
|
@configuration ||= Configuration.new
|
24
20
|
end
|
25
21
|
|
26
|
-
def
|
22
|
+
def routes(router)
|
27
23
|
Healthcheck::Router.mount(router)
|
28
24
|
end
|
29
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- linqueta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,15 +131,14 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- README.md
|
133
133
|
- app/controllers/healthcheck/healthchecks_controller.rb
|
134
|
+
- lib/generators/healthcheck/install_generator.rb
|
134
135
|
- lib/healthcheck.rb
|
135
136
|
- lib/healthcheck/check.rb
|
136
137
|
- lib/healthcheck/checker.rb
|
137
138
|
- lib/healthcheck/configuration.rb
|
138
139
|
- lib/healthcheck/engine.rb
|
139
140
|
- lib/healthcheck/error.rb
|
140
|
-
- lib/healthcheck/railtie.rb
|
141
141
|
- lib/healthcheck/router.rb
|
142
|
-
- lib/healthcheck/tasks/setup.rake
|
143
142
|
- lib/healthcheck/version.rb
|
144
143
|
- lib/rails-healthcheck.rb
|
145
144
|
homepage: https://github.com/linqueta/rails-healthcheck
|
data/lib/healthcheck/railtie.rb
DELETED
@@ -1,66 +0,0 @@
|
|
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
|