quietus 0.0.1 → 1.0.0

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: e51bf8e5b702a8806145d97e38942c57af10f020
4
- data.tar.gz: 9e91b5c2c85dc0df3c20ee38991c418deeeda022
3
+ metadata.gz: f3a5cc3af003537f8103ca7f78e41d5a38fdec69
4
+ data.tar.gz: 9e34862bc1838775b621a9d909c220a9a7f0379d
5
5
  SHA512:
6
- metadata.gz: 64c4ee237f9c576bf16105c3cd92cd4d3593922f1b9ef861837308e52f5acb9bb474532f439f9bc8d23d7c8314d22832030fa82c1d054ca25151586c973f0caf
7
- data.tar.gz: 924f4d57f7bd05a92f4006ba7149216b64c918e83305c8991c7ad925ecc33ee8a4c933f5e2e32a22b24a712aa01ac4299390ebe7378082e291be04deaaefabf6
6
+ metadata.gz: 8f91b27aed0aa89614aec2a1c2ebb601695612bb698b541c56a7ae244b3593d7ca485e3b36451affb865fa7dbe71660e25577ff0a58a8ace575ff96e4e3d7793
7
+ data.tar.gz: 9661023616de348ab98c430dac8e2f1bd0427cf69d0f07c8a866a0ca1846a3ac20e5c0c94c917fea119eb5ae2d576e8079d9b71c9a5fb67e79d53d8dc11c7976
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - robert.kenny@bbc.co.uk
9
+ on_failure: change
10
+ on_success: never
data/README.md CHANGED
@@ -1,4 +1,36 @@
1
- quietus
1
+ Quietus
2
2
  =======
3
3
 
4
4
  Simple status check web server.
5
+
6
+ [![Build Status](https://travis-ci.org/BBC-News/quietus.png?branch=master)](https://travis-ci.org/BBC-News/quietus) [![Gem Version](https://badge.fury.io/rb/quietus.png)](http://badge.fury.io/rb/quietus)
7
+
8
+ ##Why
9
+
10
+ You might want to use this to provide a status check to an AWS ELB where you don't have a web server in your app. Having a status check lets you quietly kill unhealthy instances and replace them.
11
+
12
+ See these [AWS Docs](http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-maintain-instance-levels.html).
13
+
14
+ ##Usage
15
+
16
+ ```rb
17
+ require 'quietus'
18
+
19
+ optional_hostname = 'localhost'
20
+ optional_port = '2347'
21
+
22
+ # quietus runs your check in a loop, so you might want to sleep
23
+ def your_status_check
24
+ sleep 1
25
+ is_my_app_healthy?
26
+ end
27
+
28
+ # quietus is blocking so you might want to run it in a thread or fork depending on your Ruby version
29
+ t = Thread.new do
30
+ Quietus::Server.new(optional_hostname, optional_port) { your_status_check }
31
+ end
32
+ ```
33
+
34
+ **The Quietus server will return a 200 if your_status_check is truthy, 500 otherwise**
35
+
36
+ By default quietus runs on port 2347.
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+ require 'quietus'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
2
10
 
@@ -1,3 +1,3 @@
1
1
  module Quietus
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/quietus.rb CHANGED
@@ -6,8 +6,8 @@ module Quietus
6
6
  attr_reader :port, :hostname
7
7
 
8
8
  def initialize(hostname = 'localhost', port = 2347)
9
- @hostname = hostname
10
- @port = port
9
+ @hostname = hostname
10
+ @port = port
11
11
 
12
12
  server &Proc.new
13
13
  end
@@ -15,25 +15,11 @@ module Quietus
15
15
  private
16
16
 
17
17
  def server(&proc)
18
- tcp_server = TCPServer.new(hostname, port)
19
-
20
- loop do
21
- socket = tcp_server.accept
22
-
23
- socket.gets
24
- respond(socket, proc)
25
- socket.close
26
- end
18
+ loop { respond if proc.call }
27
19
  end
28
20
 
29
- def respond(socket, proc)
30
- response = proc.call ? '200 OK' : '500 Internal Server Error'
31
- socket.print "HTTP/1.0 #{response}\r\n" +
32
- "Content-Type: text/plain\r\n" +
33
- "Content-Length: #{response.bytesize}\r\n" +
34
- "Connection: close\r\n"
35
- socket.print "\r\n"
36
- socket.print "#{response}"
21
+ def respond
22
+ TCPServer.open(hostname, port) { |s| s.accept.close }
37
23
  end
38
24
  end
39
25
  end
data/quietus.gemspec CHANGED
@@ -17,4 +17,6 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.add_development_dependency "bundler", "~> 1.6"
19
19
  spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "pry"
21
+ spec.add_development_dependency "rspec"
20
22
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'socket'
3
+
4
+ describe Quietus::Server do
5
+ context "creating" do
6
+
7
+ context "passed a falsy block" do
8
+ it "refuses a TCP connection" do
9
+ pid = fork do
10
+ Signal.trap("HUP") { exit }
11
+ Quietus::Server.new { false }
12
+ end
13
+
14
+ sleep 1
15
+
16
+ expect { TCPSocket.new('localhost', 2347) }.to raise_error(Errno::ECONNREFUSED)
17
+
18
+ Process.kill("HUP", pid)
19
+ Process.wait
20
+ end
21
+ end
22
+
23
+ context "passed a truthy block" do
24
+ it "allows a TCP connection" do
25
+ pid = fork do
26
+ Signal.trap("HUP") { exit }
27
+ Quietus::Server.new { true }
28
+ end
29
+
30
+ sleep 1
31
+
32
+ expect { TCPSocket.new('localhost', 2347) }.not_to raise_error
33
+
34
+ Process.kill("HUP", pid)
35
+ Process.wait
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'pry'
4
+ require 'quietus'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quietus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Kenny
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description:
42
70
  email:
43
71
  - kenoir@gmail.com
@@ -46,14 +74,16 @@ extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
76
  - .gitignore
77
+ - .travis.yml
49
78
  - Gemfile
50
79
  - LICENSE
51
- - LICENSE.txt
52
80
  - README.md
53
81
  - Rakefile
54
82
  - lib/quietus.rb
55
83
  - lib/quietus/version.rb
56
84
  - quietus.gemspec
85
+ - spec/quietus_spec.rb
86
+ - spec/spec_helper.rb
57
87
  homepage: https://github.com/kenoir/quietus
58
88
  licenses:
59
89
  - GPLv3
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Robert Kenny
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.