rack-health 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rack/health.rb +26 -0
  2. metadata +96 -0
@@ -0,0 +1,26 @@
1
+ module Rack
2
+ class Health
3
+ def initialize(app, options={})
4
+ @app = app
5
+ @options = {
6
+ :path => '/rack_health',
7
+ :sick_if => lambda { false },
8
+ :body => lambda {|healthy| %Q(Rack::Health says "#{healthy ? 'healthy' : 'sick'}") },
9
+ :status => lambda {|healthy| healthy ? 200 : 503 },
10
+ :headers => lambda {|healthy| {'Content-Type' => 'text/plain'} }
11
+ }.merge(options)
12
+ end
13
+
14
+ def call(env)
15
+ if env['PATH_INFO'] == @options[:path]
16
+ healthy = !@options[:sick_if].call
17
+ status = @options[:status].call(healthy)
18
+ body = [@options[:body].call(healthy)]
19
+ headers = @options[:headers].call(healthy)
20
+ [status, headers, body]
21
+ else
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-health
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Issei Naruta
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-12-17 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 31
29
+ segments:
30
+ - 1
31
+ - 2
32
+ - 0
33
+ version: 1.2.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 2
47
+ - 0
48
+ - 0
49
+ version: 2.0.0
50
+ type: :development
51
+ version_requirements: *id002
52
+ description: description
53
+ email: naruta@cookpad.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - lib/rack/health.rb
62
+ homepage: https://github.com/mirakui/rack-health
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: summary
95
+ test_files: []
96
+