dyno-battery 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "heroku"
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.5.1"
9
+ gem "rcov", ">= 0"
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 fedesoria
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = dyno-battery
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to dyno-battery
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 fedesoria. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "dyno-battery"
16
+ gem.homepage = "http://github.com/fedesoria/dyno-battery"
17
+ gem.license = "MIT"
18
+ gem.summary = "Submit request operations for dyno calculations on Heroku"
19
+ gem.description = "Submit request operations for dyno calculations on Heroku"
20
+ gem.email = "federico@dospuntocero.com.mx"
21
+ gem.authors = ["fedesoria"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'heroku'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "dyno-battery #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,60 @@
1
+ class DynoBattery
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ def call(env)
7
+ dup._call(env)
8
+ end
9
+
10
+ def _call(env)
11
+ @start = Time.now
12
+ @status, @headers, @response = @app.call(env)
13
+ @stop = Time.now
14
+ if defined?(DYNOBATTERY_ID)
15
+ req = Rack::Request.new(env)
16
+ @params = req.params
17
+ if env["PATH_INFO"] =~ /^\/add_dyno/ and @params["id"] == DYNOBATTERY_ID
18
+ add_dyno
19
+ [@status, @headers, @response]
20
+ elsif env["PATH_INFO"] =~ /^\/remove_dyno/ and @params["id"] == DYNOBATTERY_ID
21
+ remove_dyno
22
+ [@status, @headers, @response]
23
+ else
24
+ uri = URI.parse("http://dyno-battery.heroku.com/")
25
+ http = Net::HTTP.new(uri.host, uri.port)
26
+ http.open_timeout = 3
27
+ http.read_timeout = 3
28
+ @dynos = env['HTTP_X_HEROKU_DYNOS_IN_USE'] || 1
29
+ http.post("/heroku","name=#{DYNOBATTERY_ID}&date=#{@start.to_s}&time=#{"%10.6f" % (@stop - @start)}&dyno=#{@dynos}")
30
+ [@status, @headers, @response]
31
+ end
32
+ else
33
+ [@status, @headers, @response]
34
+ end
35
+ end
36
+
37
+
38
+
39
+
40
+
41
+
42
+ def add_dyno
43
+ setup_heroku_client
44
+ @heroku.set_dynos(@heroku_app[:name],@heroku_app[:dynos] + 1)
45
+ end
46
+
47
+ def remove_dyno
48
+ setup_heroku_client
49
+ @heroku.set_dynos(@heroku_app[:name],@heroku_app[:dynos] - 1)
50
+ end
51
+
52
+ def setup_heroku_client
53
+ @heroku = Heroku::Client.new(DYNO_USER, DYNO_PASSWORD)
54
+ @heroku_app = @heroku.info(DYNO_DOMAIN)
55
+ end
56
+
57
+ end
58
+
59
+
60
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'dyno-battery'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestDynoBattery < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dyno-battery
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - fedesoria
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-10 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ segments:
26
+ - 0
27
+ version: "0"
28
+ prerelease: false
29
+ type: :runtime
30
+ name: heroku
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ requirement: &id002 !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ segments:
38
+ - 0
39
+ version: "0"
40
+ prerelease: false
41
+ type: :development
42
+ name: shoulda
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ requirement: &id003 !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 1
51
+ - 0
52
+ - 0
53
+ version: 1.0.0
54
+ prerelease: false
55
+ type: :development
56
+ name: bundler
57
+ version_requirements: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 1
65
+ - 5
66
+ - 1
67
+ version: 1.5.1
68
+ prerelease: false
69
+ type: :development
70
+ name: jeweler
71
+ version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ requirement: &id005 !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ prerelease: false
81
+ type: :development
82
+ name: rcov
83
+ version_requirements: *id005
84
+ - !ruby/object:Gem::Dependency
85
+ requirement: &id006 !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ prerelease: false
93
+ type: :runtime
94
+ name: heroku
95
+ version_requirements: *id006
96
+ description: Submit request operations for dyno calculations on Heroku
97
+ email: federico@dospuntocero.com.mx
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ files:
106
+ - .document
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - lib/dyno-battery.rb
113
+ - test/helper.rb
114
+ - test/test_dyno-battery.rb
115
+ has_rdoc: true
116
+ homepage: http://github.com/fedesoria/dyno-battery
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.3.6
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Submit request operations for dyno calculations on Heroku
145
+ test_files:
146
+ - test/helper.rb
147
+ - test/test_dyno-battery.rb