wellness 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4552f48d89fb5d5af48f8356e21ed8f7639cee90
4
- data.tar.gz: a01ecec7812e71fd197b4001e449a786de18bf34
3
+ metadata.gz: cc67d265fe3b43ff86c235e0317c32e20ccd0971
4
+ data.tar.gz: d7a96511cebbaeee9926489760d3bcf7667227f9
5
5
  SHA512:
6
- metadata.gz: a4eae8f146fae81f2c589c7ac131999eed458923828e13633bff0559c578763c37aa85806cc71e013e51cd04694d7d162c25b5399728864bfdefe4de575d5190
7
- data.tar.gz: cdef3cb99af66fd8c7565f5bd9a1b88a8108f368915ecc2aa3cac8585dc1cad64fe359b44dfffed2ded92252ff7d545ac93933975fca0098af7838d71d99b23f
6
+ metadata.gz: ee1f255adf40cdd1f3ba90a31e28ae4f8b0fb5c9b6e9d31eb23f41c9646e71c0d53cf415ba8d9170b537a96eaea7c44fce3214aebab15c71bba0fe491b02cda3
7
+ data.tar.gz: 368f138e36a57ae792b92f9d7d6d2d934033a64219aef4686c99945c93f115bf982a096d54f09eef63b76207028d162288eb24f4497aa6f0d94e6ba003e984d4
data/README.md CHANGED
@@ -32,7 +32,7 @@ redis = Wellness::Services::RedisService.new({
32
32
  })
33
33
  system.add_service('database', pg)
34
34
  system.add_service('redis', redis)
35
- config.middleware.insert_before('::ActiveRecord::QueryCache', 'Wellness::Checker', system)
35
+ config.middleware.insert_before('::ActiveRecord::QueryCache', 'Wellness::Middleware', system)
36
36
  ```
37
37
 
38
38
  ## Usage - Sinatra
@@ -56,7 +56,44 @@ redis = Wellness::Services::RedisService.new({
56
56
  system.add_service('database', pg)
57
57
  system.add_service('redis', redis)
58
58
 
59
- use(Wellness::Checker, system)
59
+ use(Wellness::Middleware, system)
60
+ ```
61
+
62
+ ## Example Response
63
+
64
+ ```json
65
+ {
66
+ "status":"UNHEALTHY",
67
+ "details":{
68
+
69
+ },
70
+ "dependencies":{
71
+ "database":{
72
+ "status":"UNHEALTHY",
73
+ "details":{
74
+ "error":"no response from ping"
75
+ }
76
+ },
77
+ "sidekiq":{
78
+ "status":"HEALTHY",
79
+ "details":{
80
+ "processed":0,
81
+ "failed":0,
82
+ "busy":0,
83
+ "enqueued":0,
84
+ "scheduled":0,
85
+ "retries":0,
86
+ "default_latency":0,
87
+ "redis":{
88
+ "uptime_in_days":"0",
89
+ "connected_clients":"1",
90
+ "used_memory_human":"979.22K",
91
+ "used_memory_peak_human":"1.02M"
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
60
97
  ```
61
98
 
62
99
  ## Custom Services
@@ -94,7 +131,7 @@ service = MyCustomService.new({foo: 'bar'})
94
131
  system.add_service('some service', service)
95
132
 
96
133
  # Load it into your rack
97
- use(Wellness::Checker, system)
134
+ use(Wellness::Middleware, system)
98
135
  ```
99
136
 
100
137
  ## Contributing
@@ -1,42 +1,7 @@
1
- module Wellness
2
-
3
- class Checker
4
- def initialize(app, system, options={})
5
- @app = app
6
- @system = system
7
-
8
- # Optional arguments
9
- @health_status_path = options[:status_path] || '/health/status'
10
- @health_details_path = options[:details_path] || '/health/details'
11
- end
12
-
13
- def call(env)
14
- case env['PATH_INFO']
15
- when @health_status_path
16
- health_status(env)
17
- when @health_details_path
18
- health_details(env)
19
- else
20
- @app.call(env)
21
- end
22
- end
1
+ require 'wellness/middleware'
23
2
 
24
- def health_status(env)
25
- if @system.check
26
- [200, {'Content-Type' => 'text/json'}, [{status: 'HEALTHY'}.to_json]]
27
- else
28
- [500, {'Content-Type' => 'text/json'}, [{status: 'UNHEALTHY'}.to_json]]
29
- end
30
-
31
- end
32
-
33
- def health_details(env)
34
- if @system.check
35
- [200, {'Content-Type' => 'text/json'}, [@system.to_json]]
36
- else
37
- [500, {'Content-Type' => 'text/json'}, [@system.to_json]]
38
- end
39
- end
40
- end
41
-
42
- end
3
+ module Wellness
4
+ # Backwards compatibility. This isn't a proper name for something that is
5
+ # supposed to be in the middleware.
6
+ Checker = Wellness::Middleware
7
+ end
@@ -0,0 +1,45 @@
1
+ module Wellness
2
+
3
+ # This is to be put into the Rack environment.
4
+ #
5
+ # @author Matthew A. Johnston
6
+ class Middleware
7
+ def initialize(app, system, options={})
8
+ @app = app
9
+ @system = system
10
+
11
+ # Optional arguments
12
+ @health_status_path = options[:status_path] || '/health/status'
13
+ @health_details_path = options[:details_path] || '/health/details'
14
+ end
15
+
16
+ def call(env)
17
+ case env['PATH_INFO']
18
+ when @health_status_path
19
+ health_status(env)
20
+ when @health_details_path
21
+ health_details(env)
22
+ else
23
+ @app.call(env)
24
+ end
25
+ end
26
+
27
+ def health_status(env)
28
+ if @system.check
29
+ [200, {'Content-Type' => 'text/json'}, [{status: 'HEALTHY'}.to_json]]
30
+ else
31
+ [500, {'Content-Type' => 'text/json'}, [{status: 'UNHEALTHY'}.to_json]]
32
+ end
33
+
34
+ end
35
+
36
+ def health_details(env)
37
+ if @system.check
38
+ [200, {'Content-Type' => 'text/json'}, [@system.to_json]]
39
+ else
40
+ [500, {'Content-Type' => 'text/json'}, [@system.to_json]]
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Wellness
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/wellness.rb CHANGED
@@ -4,4 +4,5 @@ end
4
4
  require 'wellness/version'
5
5
  require 'wellness/services/base'
6
6
  require 'wellness/system'
7
+ require 'wellness/middleware'
7
8
  require 'wellness/checker'
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Wellness::Checker do
3
+ describe Wellness::Middleware do
4
4
  pending
5
5
  end
data/wellness.gemspec CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency('rack', '~> 1.5')
22
-
23
21
  spec.add_development_dependency('bundler', '~> 1.3')
24
22
  spec.add_development_dependency('rake')
25
23
  spec.add_development_dependency('rspec')
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wellness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Johnston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.5'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '1.5'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +68,7 @@ files:
82
68
  - Rakefile
83
69
  - lib/wellness.rb
84
70
  - lib/wellness/checker.rb
71
+ - lib/wellness/middleware.rb
85
72
  - lib/wellness/services/base.rb
86
73
  - lib/wellness/services/postgres_service.rb
87
74
  - lib/wellness/services/redis_service.rb