rack-heartbeat 1.0.1 → 1.1.0
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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/README.md +16 -4
- data/lib/rack/heartbeat.rb +27 -1
- data/lib/rack/heartbeat/railtie.rb +1 -1
- data/rack-heartbeat.gemspec +1 -1
- data/test/rack/test_heartbeat.rb +16 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a90f7d887de31bbd1e56ad6cd7c2bd56b687bd
|
4
|
+
data.tar.gz: f2c3265b628de9751f39a5dbd4154bb715a0f6cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d55562bbed3240a828643da60cde037d6314bfe0fcc156ed26a94c184ea8ff14922c5bb6abcde089792817cd6bd2956e27423e852533bbc350aafa6cf5ae7dc3
|
7
|
+
data.tar.gz: c114fe9638a07a1cc81ad7f0f2217a6f505fa756aaf230105721c3c0eedff8add55e3915e08976c287b5c8fde9be22ba6a661ec93821339da1c69ddbc4e46008
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.bundle
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rack::Heartbeat
|
2
2
|
|
3
|
-
A tiny gem that installs a Rack middleware to respond to heartbeat requests.
|
3
|
+
A tiny gem that installs a Rack middleware to respond to heartbeat requests. This saves you all the trouble of creating custom controllers, routes, and static files, and prevents your logs from bloating.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,17 +18,28 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Once the gem is installed, you're done. Just browse to localhost:
|
21
|
+
Once the gem is installed, you're done. Just browse to http://localhost:3000/heartbeat to get a text response with "OK".
|
22
22
|
|
23
23
|
If you want to customize the url for any reason, you can configure that, too:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
#config/initializers/rack_heartbeat.rb
|
26
|
+
# config/initializers/rack_heartbeat.rb
|
27
27
|
Rack::Heartbeat.setup do |config|
|
28
28
|
config.heartbeat_path = 'health-check.txt'
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
+
You can also customize headers and response, for example if you want to do the cross-domain request, you can
|
33
|
+
either set the CORS headers, or just send an image:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# config/initializers/rack_heartbeat.rb
|
37
|
+
Rack::Heartbeat.setup do |config|
|
38
|
+
config.heartbeat_response = Base64.decode64('R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')
|
39
|
+
config.heartbeat_headers = {'Content-Type' => 'image/gif'}
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
32
43
|
## Contributing
|
33
44
|
|
34
45
|
1. Fork it
|
@@ -40,4 +51,5 @@ end
|
|
40
51
|
## Contributors
|
41
52
|
|
42
53
|
* [James Cox](https://github.com/imajes)
|
43
|
-
* [Steve Mitchell](
|
54
|
+
* [Steve Mitchell](https://github.com/theSteveMitchell)
|
55
|
+
* [Igor Rzegocki](https://github.com/ajgon)
|
data/lib/rack/heartbeat.rb
CHANGED
@@ -4,15 +4,33 @@ module Rack
|
|
4
4
|
|
5
5
|
class Heartbeat
|
6
6
|
@@heartbeat_path = 'heartbeat'
|
7
|
+
@@heartbeat_response = 'OK'
|
8
|
+
@@heartbeat_headers = {"Content-Type" => "text/plain"}
|
7
9
|
|
8
10
|
class << self
|
9
11
|
def heartbeat_path
|
10
12
|
@@heartbeat_path
|
11
13
|
end
|
12
14
|
|
15
|
+
def heartbeat_response
|
16
|
+
@@heartbeat_response
|
17
|
+
end
|
18
|
+
|
19
|
+
def heartbeat_headers
|
20
|
+
@@heartbeat_headers
|
21
|
+
end
|
22
|
+
|
13
23
|
def heartbeat_path=(path)
|
14
24
|
@@heartbeat_path = path
|
15
25
|
end
|
26
|
+
|
27
|
+
def heartbeat_response=(response)
|
28
|
+
@@heartbeat_response = response
|
29
|
+
end
|
30
|
+
|
31
|
+
def heartbeat_headers=(headers_hash)
|
32
|
+
@@heartbeat_headers = headers_hash
|
33
|
+
end
|
16
34
|
end
|
17
35
|
|
18
36
|
def initialize(app)
|
@@ -22,7 +40,7 @@ module Rack
|
|
22
40
|
def call(env)
|
23
41
|
if env['PATH_INFO'] == "/#{heartbeat_path}"
|
24
42
|
NewRelic::Agent.ignore_transaction if defined? NewRelic
|
25
|
-
[200,
|
43
|
+
[200, heartbeat_headers, [heartbeat_response]]
|
26
44
|
else
|
27
45
|
@app.call(env)
|
28
46
|
end
|
@@ -32,6 +50,14 @@ module Rack
|
|
32
50
|
self.class.heartbeat_path
|
33
51
|
end
|
34
52
|
|
53
|
+
def heartbeat_response
|
54
|
+
self.class.heartbeat_response
|
55
|
+
end
|
56
|
+
|
57
|
+
def heartbeat_headers
|
58
|
+
self.class.heartbeat_headers
|
59
|
+
end
|
60
|
+
|
35
61
|
def self.setup
|
36
62
|
yield self
|
37
63
|
end
|
data/rack-heartbeat.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = "rack-heartbeat"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = '1.0
|
15
|
+
gem.version = '1.1.0'
|
16
16
|
|
17
17
|
gem.add_development_dependency('minitest')
|
18
18
|
gem.add_development_dependency('rack-test')
|
data/test/rack/test_heartbeat.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'base64'
|
2
3
|
|
3
4
|
class Rack::TestHeartbeat < Minitest::Test
|
4
5
|
def setup
|
@@ -9,7 +10,9 @@ class Rack::TestHeartbeat < Minitest::Test
|
|
9
10
|
def teardown
|
10
11
|
Rack::Heartbeat.setup do |config|
|
11
12
|
config.heartbeat_path = 'heartbeat'
|
12
|
-
|
13
|
+
config.heartbeat_headers = {'Content-Type' => 'text/plain'}
|
14
|
+
config.heartbeat_response = 'OK'
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
15
18
|
def test_initialize_sets_default_heartbeat_path
|
@@ -47,11 +50,20 @@ class Rack::TestHeartbeat < Minitest::Test
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def test_setup_configures_heartbeat_path
|
50
|
-
|
53
|
+
expected_path = 'health-check.txt'
|
54
|
+
expected_headers = {'Content-Type' => 'image/gif'}
|
55
|
+
expected_response = Base64.decode64('R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')
|
56
|
+
env = {'PATH_INFO' => "/#{expected_path}"}
|
57
|
+
|
51
58
|
Rack::Heartbeat.setup do |config|
|
52
|
-
config.heartbeat_path =
|
59
|
+
config.heartbeat_path = expected_path
|
60
|
+
config.heartbeat_headers = expected_headers
|
61
|
+
config.heartbeat_response = expected_response
|
53
62
|
end
|
54
63
|
|
55
|
-
assert_match
|
64
|
+
assert_match expected_path, Rack::Heartbeat.heartbeat_path
|
65
|
+
assert_equal expected_headers, Rack::Heartbeat.heartbeat_headers
|
66
|
+
assert_equal expected_response, Rack::Heartbeat.heartbeat_response
|
67
|
+
assert_equal [200, expected_headers, [expected_response]], @heartbeat.call(env)
|
56
68
|
end
|
57
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-heartbeat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Cox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -61,6 +61,8 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
64
66
|
- Gemfile
|
65
67
|
- LICENSE
|
66
68
|
- README.md
|
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
version: '0'
|
91
93
|
requirements: []
|
92
94
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.1
|
94
96
|
signing_key:
|
95
97
|
specification_version: 4
|
96
98
|
summary: provides a simple endpoint for your rails app for a heartbeat client to connect
|