keep_alive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.2" > .rvmrc
9
+ environment_id="ruby-1.9.2-p290@ad"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.5 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in keep_alive.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 A D Vishnu Prasad
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,45 @@
1
+ # KeepAlive
2
+
3
+ Gem that will tell you whether the app/db is alive or not
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'keep_alive'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install keep_alive
18
+
19
+ ## Usage
20
+ add the following in initializers/keep_alive.rb
21
+
22
+ KeepAlive.config do |config|
23
+ config.model(ModelName)
24
+ end
25
+
26
+ in routes.rb
27
+
28
+ keep_alive
29
+
30
+ How to use ?
31
+
32
+ localhost:3000/keep_alive
33
+
34
+ When to use ?
35
+
36
+ You can use this url for your performance monitoring tool like NewRelic.
37
+ So that NewRelic will not hit homepage for every 10 secs or so.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ module KeepAlive
2
+ class KeepAliveController < ActionController::Base
3
+ unloadable #http://apidock.com/rails/ActiveSupport/Dependencies/Loadable/unloadable
4
+
5
+ def index
6
+ no_of_rows = KeepAlive.config.no_of_rows
7
+ respond_to do |format|
8
+ format.xml { render :xml => {:total => no_of_rows}.to_xml(:root => "keep_alive")}
9
+ format.json { render :json => {:keep_alive => {:total => no_of_rows}}}
10
+ format.html { render :text => "Number of rows : #{no_of_rows}"}
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module KeepAlive
2
+ class KeepAliveController < ActionController::Base
3
+ unloadable #http://apidock.com/rails/ActiveSupport/Dependencies/Loadable/unloadable
4
+
5
+ def index
6
+ no_of_rows = KeepAlive.config.no_of_rows
7
+
8
+ respond_to do |format|
9
+ format.xml { render :xml => {:total => no_of_rows}.to_xml(:root => "keep_alive")}
10
+ format.json { render :json => {:keep_alive => {:total => no_of_rows}}}
11
+ format.html { render :text => "No Of Rows : #{no_of_rows}"}
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'keep_alive/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "keep_alive"
8
+ gem.version = KeepAlive::VERSION
9
+ gem.authors = ["A D Vishnu Prasad"]
10
+ gem.email = ["advishnuprasad@gmail.com"]
11
+ gem.description = %q{Gem that will give you whether the app & db is alive or not}
12
+ gem.summary = %q{Gem that will give you whether the app & db is alive or not}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ # gem.add_development_dependency 'rake'
20
+ # gem.add_development_dependency 'rspec'
21
+ gem.add_runtime_dependency "rails", ">= 3.0.1"
22
+ end
data/lib/keep_alive.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "keep_alive/version"
2
+ require 'keep_alive/action_dispatch'
3
+ require "keep_alive/engine"
4
+ require 'keep_alive/config'
5
+ module KeepAlive
6
+ def self.config
7
+ @config ||= KeepAlive::Config.new
8
+ yield(@config) if block_given?
9
+ @config
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module KeepAlive
2
+ module ActionDispatch
3
+ def keep_alive
4
+ self.get "/keep_alive", :controller => "keep_alive/keep_alive", :action => "index"
5
+ end
6
+ end
7
+ end
8
+
9
+ ActionDispatch::Routing::Mapper.send(:include, KeepAlive::ActionDispatch)
@@ -0,0 +1,18 @@
1
+ module KeepAlive
2
+ class Config
3
+ attr_reader :no_of_rows
4
+ attr_accessor :model_name
5
+ def initialize
6
+ @no_of_rows = 0
7
+ @model_name = ""
8
+ end
9
+
10
+ def model(*model)
11
+ @model_name = model
12
+ end
13
+
14
+ def no_of_rows
15
+ @no_of_rows = @model_name.count
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require "rails"
2
+ module KeepAlive
3
+ class Engine < Rails::Engine
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module KeepAlive
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1 @@
1
+ require 'keep_alive'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keep_alive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - A D Vishnu Prasad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.1
30
+ description: Gem that will give you whether the app & db is alive or not
31
+ email:
32
+ - advishnuprasad@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rvmrc
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - app/controllers/keep_alive/keep_alive_controller.rb
44
+ - app/controllers/keep_alive_controller.rb
45
+ - keep_alive.gemspec
46
+ - lib/keep_alive.rb
47
+ - lib/keep_alive/action_dispatch.rb
48
+ - lib/keep_alive/config.rb
49
+ - lib/keep_alive/engine.rb
50
+ - lib/keep_alive/version.rb
51
+ - spec/lib/keep_alive_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: -890469389
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: -890469389
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.24
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Gem that will give you whether the app & db is alive or not
83
+ test_files:
84
+ - spec/lib/keep_alive_spec.rb
85
+ - spec/spec_helper.rb