nimble_nodes 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -17,7 +17,6 @@ In config/enviroment.rb
17
17
  config.gem 'nimble_nodes'
18
18
  config.middleware.use NimbleNodes::Middleware
19
19
 
20
- ENV['NN_TOKEN'] = 'api_token_for_app'
21
20
 
22
21
  == Copyright
23
22
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -2,6 +2,10 @@ module NimbleNodes
2
2
 
3
3
  module Dynos
4
4
 
5
+ def self.size
6
+ ENV['NN_DYNOS_POOL_SIZE']
7
+ end
8
+
5
9
  def self.max
6
10
  ENV['NN_DYNOS_POOL_MAX']
7
11
  end
@@ -0,0 +1,15 @@
1
+ module NimbleNodes
2
+
3
+ module Filter
4
+
5
+ # Use as a before_filter
6
+ def monitor_heroku_app
7
+ NimbleNodes.monitor(request.env)
8
+ end
9
+
10
+
11
+ end
12
+
13
+ end
14
+
15
+ ActionController::Base.send(:include, NimbleNodes::Filter)
@@ -6,8 +6,7 @@ module NimbleNodes
6
6
 
7
7
 
8
8
  def call(env)
9
- @report = NimbleNodes::Report.new(env)
10
- @report.post if @report.post?
9
+ NimbleNodes.monitor(env)
11
10
  # now, execute the request using our Rails app
12
11
  response = @app.call(env)
13
12
  end
@@ -1,21 +1,27 @@
1
1
  module NimbleNodes
2
2
 
3
3
  class Report
4
+
5
+
6
+ def self.path
7
+ "/#{ENV['NN_APP_NAME']}/dynos/reports.json"
8
+ end
9
+
4
10
  def initialize(env)
5
11
  @dynos_in_use = env['HTTP_X_HEROKU_DYNOS_IN_USE']
6
- @request_queue_depth = env['HTTP_X_HEROKU_QUEUE_DEPTH']
12
+ @request_queue_depth = env['HTTP_X_HEROKU_QUEUE_DEPTH']
7
13
  end
8
14
 
9
15
  def post
10
16
  params = {
11
17
  :dynos_in_use => @dynos_in_use,
12
18
  :request_queue_size => @request_queue_depth }
13
- NimbleNodes::Server.post('/dynos/reports.json', params)
19
+ NimbleNodes::Server.post(self.class.path, params)
14
20
  end
15
21
 
16
22
  def post?
17
- return true
18
- dynos_maxed_out? or queue_depth_too_long?
23
+ return false if ENV['NN_APP_PAUSED_AT']
24
+ dynos_maxed_out? or queue_depth_too_long? or unused_dynos?
19
25
  end
20
26
 
21
27
  def dynos_maxed_out?
@@ -27,6 +33,11 @@ module NimbleNodes
27
33
  return false if @request_queue_depth.nil?
28
34
  @request_queue_depth > Dynos.max_request_queue
29
35
  end
36
+
37
+ def unused_dynos?
38
+ return false if @dynos_in_use.nil?
39
+ @dynos_in_use < Dynos.size
40
+ end
30
41
 
31
42
  end
32
43
 
@@ -7,7 +7,7 @@ module NimbleNodes
7
7
  def self.post(path,args)
8
8
  url = URI.parse(url_to(path))
9
9
  request = Net::HTTP::Post.new(url.path)
10
- request.set_form_data({:token => ENV['NN_TOKEN'], :json => args.to_json })
10
+ request.set_form_data({:token => ENV['NN_APP_TOKEN'], :json => args.to_json, :created_at => Time.now })
11
11
  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
12
12
  end
13
13
 
data/lib/nimble_nodes.rb CHANGED
@@ -1,10 +1,31 @@
1
1
  module NimbleNodes
2
+
3
+ # returns array of files
4
+ def self.files
5
+ files = %w(dynos report server)
6
+ files.push NimbleNodes.legacy? ? 'filter' : 'middleware'
7
+ files
8
+ end
9
+
10
+ # returns true if gem is loaded in a pre 2.3 version of rails
11
+ def self.legacy?
12
+ defined?(RAILS_GEM_VERSION) and RAILS_GEM_VERSION.slice(0..2).to_f < 2.3
13
+ end
14
+
15
+ #= Monitoring
16
+ # pass over the hash containing Rack env variables
17
+ # a Report will be created and posted if neccessary
18
+ def monitor(env)
19
+ report = NimbleNodes::Report.new(env)
20
+ report.post if report.post?
21
+ end
22
+
2
23
  end
3
24
 
25
+ NimbleNodes.files.each { |file| require File.dirname(__FILE__) + "/nimble_nodes/#{file}" }
4
26
 
5
- current_path = File.dirname(__FILE__)
6
27
 
7
- %w(dynos report server middleware).each do |file|
8
- require "#{current_path}/nimble_nodes/#{file}"
9
- end
28
+
29
+
30
+
10
31
 
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nimble_nodes}
8
+ s.version = "0.1.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jordan Glasner"]
12
+ s.date = %q{2010-03-11}
13
+ s.description = %q{automatically scales dynos and workers at Heroku}
14
+ s.email = %q{jordan@digitalignition.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/nimble_nodes.rb",
27
+ "lib/nimble_nodes/dynos.rb",
28
+ "lib/nimble_nodes/filter.rb",
29
+ "lib/nimble_nodes/middleware.rb",
30
+ "lib/nimble_nodes/report.rb",
31
+ "lib/nimble_nodes/server.rb",
32
+ "nimble_nodes.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_nimble_nodes.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/glasner/nimble_nodes}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{gem for connecting apps to the NimbleNodes server}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_nimble_nodes.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ end
58
+ end
59
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nimble_nodes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Glasner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-03 00:00:00 -05:00
12
+ date: 2010-03-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,11 @@ files:
40
40
  - VERSION
41
41
  - lib/nimble_nodes.rb
42
42
  - lib/nimble_nodes/dynos.rb
43
+ - lib/nimble_nodes/filter.rb
43
44
  - lib/nimble_nodes/middleware.rb
44
45
  - lib/nimble_nodes/report.rb
45
46
  - lib/nimble_nodes/server.rb
47
+ - nimble_nodes.gemspec
46
48
  - test/helper.rb
47
49
  - test/test_nimble_nodes.rb
48
50
  has_rdoc: true