rails-health-check 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/README.md +19 -0
- data/Rakefile +6 -0
- data/VERSION +1 -0
- data/lib/rails-health-check.rb +3 -0
- data/lib/rails-health-check/middleware.rb +61 -0
- data/lib/rails-health-check/railtie.rb +7 -0
- data/rails-health-check.gemspec +20 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07f08bf896120383b79826fe4bb10541280c44de
|
4
|
+
data.tar.gz: b53071714355fd4799dee721c4b23faaa8333a10
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f94a84277c894b2210cecc27383a9d8a0cd1c774be33b07d047a8360fec38c3f7ea17d4e40d7e9b0e5396c2a327e6afe92b27304540cb35545723b8b055b74e7
|
7
|
+
data.tar.gz: 7d5d6bb49ea82d1598c3d41811ff8d8399ee78656ab086e8495be63cd01386a9d721b39f6ca462b1edf70ebbff9a16e12d924727460c49566d25ee66984598a3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Rails Config Loaders
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
The gem is a simple solution if you want health check apis of latency and database.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Put this into your Gemfile
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem 'rails-health-check'
|
13
|
+
```
|
14
|
+
|
15
|
+
and run ``bundle install``.
|
16
|
+
|
17
|
+
2. Start your rails application.
|
18
|
+
|
19
|
+
3. visit `/health/latency` and `/health/db`
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module RailsHealthCheck
|
2
|
+
class Middleware
|
3
|
+
|
4
|
+
def initialize(app, options={})
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
if env['REQUEST_METHOD'] == 'GET' && health_path?(env['PATH_INFO'])
|
10
|
+
if health_latency_path?(env['PATH_INFO'])
|
11
|
+
health_latency_response
|
12
|
+
elsif health_db_path?(env['PATH_INFO'])
|
13
|
+
health_db_response
|
14
|
+
end
|
15
|
+
else
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def health_path?(request_path)
|
23
|
+
health_latency_path?(request_path) || health_db_path?(request_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def health_latency_path?(request_path)
|
27
|
+
request_path == '/health/latency'
|
28
|
+
end
|
29
|
+
|
30
|
+
def health_db_path?(request_path)
|
31
|
+
request_path == '/health/db'
|
32
|
+
end
|
33
|
+
|
34
|
+
def health_latency_response
|
35
|
+
# [status, headers, body]
|
36
|
+
[200, { 'Content-Type' => 'application/json' }, [{ msg: 'ok' }.to_json]]
|
37
|
+
end
|
38
|
+
|
39
|
+
def health_db_response
|
40
|
+
begin
|
41
|
+
validate_migration
|
42
|
+
|
43
|
+
status = 200
|
44
|
+
msg = 'ok'
|
45
|
+
rescue => e
|
46
|
+
status = 500
|
47
|
+
msg = e.message
|
48
|
+
end
|
49
|
+
|
50
|
+
# [status, headers, body]
|
51
|
+
[status, { 'Content-Type' => 'application/json' }, [{ msg: msg }.to_json]]
|
52
|
+
end
|
53
|
+
|
54
|
+
def validate_migration
|
55
|
+
# Check connection to the DB and needs migration or not
|
56
|
+
if ActiveRecord::Migrator.needs_migration?
|
57
|
+
raise 'Schema is not latest!'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
version = File.read(File.expand_path('../VERSION', __FILE__)).strip
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = 'rails-health-check'
|
6
|
+
s.version = version
|
7
|
+
s.summary = 'Health check for Rails'
|
8
|
+
s.description = 'It is a health check tool for Rails.'
|
9
|
+
s.licenses = ['Nonstandard']
|
10
|
+
s.authors = ['ChouAndy']
|
11
|
+
s.email = ['chouandy625@gmail.com']
|
12
|
+
s.homepage = 'https://github.com/chouandy/rails-health-check'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
|
17
|
+
s.required_ruby_version = '>= 1.9.3'
|
18
|
+
|
19
|
+
s.add_dependency 'rails', '>= 4.2'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-health-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ChouAndy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: It is a health check tool for Rails.
|
28
|
+
email:
|
29
|
+
- chouandy625@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- Gemfile
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- lib/rails-health-check.rb
|
41
|
+
- lib/rails-health-check/middleware.rb
|
42
|
+
- lib/rails-health-check/railtie.rb
|
43
|
+
- rails-health-check.gemspec
|
44
|
+
homepage: https://github.com/chouandy/rails-health-check
|
45
|
+
licenses:
|
46
|
+
- Nonstandard
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.9.3
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.6.8
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Health check for Rails
|
68
|
+
test_files: []
|