alive_state 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +9 -0
- data/alive_state.gemspec +23 -0
- data/lib/alive_state/application.rb +18 -0
- data/lib/alive_state/configure.rb +17 -0
- data/lib/alive_state/default.rb +20 -0
- data/lib/alive_state/middleware.rb +53 -0
- data/lib/alive_state/rails.rb +25 -0
- data/lib/alive_state/registry.rb +13 -0
- data/lib/alive_state/version.rb +3 -0
- data/lib/alive_state.rb +37 -0
- data/spec/alive_state_spec.rb +15 -0
- data/spec/lib/version_spec.rb +9 -0
- data/spec/spec_helper.rb +4 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95e7e5d9aabd6fb3b40082ebcef38abe1a2e11a8
|
4
|
+
data.tar.gz: 62ba4b09069d35cfa5872b80192a4e9788c7e4ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7336e283cff3ff2d5b4053ef4af38b87fe706eda999300bb4bba6190b3028812409185f156477f2d52c6ea982fea0270715345e811408104b4dfe466656182ff
|
7
|
+
data.tar.gz: ab0fde52c34a423561fa580be3d8e1e47ade23b9fd2b137bf96d9a2f66085bae3e04cd4e260438e482aee8c7eeba40348bea89e653af399b52400cbe126c430f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ogom
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Alive State
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/ogom/alive_state.png?branch=master)](https://travis-ci.org/ogom/alive_state)
|
4
|
+
|
5
|
+
Alive Application State on Rails.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'alive_state'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
* MIT
|
data/Rakefile
ADDED
data/alive_state.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alive_state/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alive_state"
|
8
|
+
spec.version = AliveState::VERSION
|
9
|
+
spec.authors = ["ogom"]
|
10
|
+
spec.email = ["ogom@hotmail.co.jp"]
|
11
|
+
spec.summary = %q{Alive Application State.}
|
12
|
+
spec.description = %q{Alive Application State on Rails.}
|
13
|
+
spec.homepage = "https://github.com/ogom/alive_state"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AliveState
|
2
|
+
module Configure
|
3
|
+
class << self
|
4
|
+
attr_accessor :path, :format
|
5
|
+
|
6
|
+
def setup
|
7
|
+
keys.each do |key|
|
8
|
+
instance_variable_set(:"@#{key}", AliveState::Default.send(key))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def keys
|
13
|
+
@keys ||= %i[path format]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AliveState
|
2
|
+
module Default
|
3
|
+
PATH = 'status'.freeze
|
4
|
+
FORMAT = 'json'.freeze
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def options
|
8
|
+
Hash[AliveState::Configure.keys.map{|key| [key, send(key)]}]
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
PATH
|
13
|
+
end
|
14
|
+
|
15
|
+
def format
|
16
|
+
FORMAT
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module AliveState
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
path, format = env['PATH_INFO'].split('.')
|
9
|
+
case path
|
10
|
+
when /^\/#{AliveState.config.path}/
|
11
|
+
alive_state_call(env, format)
|
12
|
+
else
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def alive_state_call(env, format)
|
18
|
+
format ||= AliveState.config.format
|
19
|
+
|
20
|
+
status = 200
|
21
|
+
params = { 'Content-Type' => 'text/plain; charset=utf-8' }
|
22
|
+
raw = {
|
23
|
+
state: :green,
|
24
|
+
created_at: Time.now,
|
25
|
+
application: {}
|
26
|
+
}
|
27
|
+
|
28
|
+
AliveState.applications.each do |application|
|
29
|
+
raw[:application][application.name] = application.alive?
|
30
|
+
end
|
31
|
+
|
32
|
+
raw[:application].keys.each do |key|
|
33
|
+
unless raw[:application][key]
|
34
|
+
raw[:state] = :red
|
35
|
+
break
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
case format
|
40
|
+
when 'json'
|
41
|
+
body = raw.to_json
|
42
|
+
params = { 'Content-Type' => 'application/json' }
|
43
|
+
when 'xml'
|
44
|
+
body = raw.to_xml
|
45
|
+
params = { 'Content-Type' => 'application/xml' }
|
46
|
+
else
|
47
|
+
body = raw.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
[status, params, [body]]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AliveState
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "alive_state.configure_rails_initialization" do
|
4
|
+
if use_alive_state?
|
5
|
+
insert_middleware
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def insert_middleware
|
10
|
+
if defined? ActionDispatch::DebugExceptions
|
11
|
+
app.middleware.insert_after ActionDispatch::DebugExceptions, AliveState::Middleware
|
12
|
+
else
|
13
|
+
app.middleware.use AliveState::Middleware
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def use_alive_state?
|
18
|
+
!Rails.env.production? and app.config.consider_all_requests_local
|
19
|
+
end
|
20
|
+
|
21
|
+
def app
|
22
|
+
Rails.application
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/alive_state.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'alive_state/version'
|
2
|
+
require 'alive_state/configure'
|
3
|
+
require 'alive_state/default'
|
4
|
+
require 'alive_state/registry'
|
5
|
+
require 'alive_state/application'
|
6
|
+
require 'alive_state/middleware'
|
7
|
+
|
8
|
+
module AliveState
|
9
|
+
class << self
|
10
|
+
def configure
|
11
|
+
yield AliveState::Configure
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
AliveState::Configure
|
16
|
+
end
|
17
|
+
|
18
|
+
def application(&block)
|
19
|
+
registry = AliveState::Registry.new
|
20
|
+
registry.instance_eval(&block)
|
21
|
+
@applications ||= []
|
22
|
+
@applications += registry.application
|
23
|
+
end
|
24
|
+
|
25
|
+
def applications
|
26
|
+
@applications
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
AliveState::Configure.setup
|
32
|
+
|
33
|
+
AliveState.application do
|
34
|
+
active_record { ActiveRecord::Base.connection.execute('select 1') }
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'alive_state/rails' if defined? Rails::Railtie
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AliveState do
|
4
|
+
it ".applications" do
|
5
|
+
expect(AliveState.applications.count).to eq(1)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "application.name" do
|
9
|
+
expect(AliveState.applications.first.name).to eq(:active_record)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "application.alive?" do
|
13
|
+
expect(AliveState.applications.first.alive?).to eq(true)
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alive_state
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ogom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Alive Application State on Rails.
|
42
|
+
email:
|
43
|
+
- ogom@hotmail.co.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- alive_state.gemspec
|
55
|
+
- lib/alive_state.rb
|
56
|
+
- lib/alive_state/application.rb
|
57
|
+
- lib/alive_state/configure.rb
|
58
|
+
- lib/alive_state/default.rb
|
59
|
+
- lib/alive_state/middleware.rb
|
60
|
+
- lib/alive_state/rails.rb
|
61
|
+
- lib/alive_state/registry.rb
|
62
|
+
- lib/alive_state/version.rb
|
63
|
+
- spec/alive_state_spec.rb
|
64
|
+
- spec/lib/version_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/ogom/alive_state
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Alive Application State.
|
90
|
+
test_files:
|
91
|
+
- spec/alive_state_spec.rb
|
92
|
+
- spec/lib/version_spec.rb
|
93
|
+
- spec/spec_helper.rb
|