resque-heroku-scaler 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +46 -12
- data/lib/resque-heroku-scaler.rb +1 -0
- data/lib/resque/plugins/{resque_heroku_scaler.rb → heroku_scaler.rb} +15 -8
- data/lib/resque/plugins/{resque_heroku_scaler → heroku_scaler}/config.rb +1 -1
- data/lib/resque/plugins/{resque_heroku_scaler → heroku_scaler}/manager.rb +2 -2
- data/lib/resque/plugins/{resque_heroku_scaler → heroku_scaler}/manager/heroku.rb +1 -1
- data/lib/resque/plugins/{resque_heroku_scaler → heroku_scaler}/manager/local.rb +1 -1
- data/lib/resque/plugins/{resque_heroku_scaler → heroku_scaler}/resque.rb +0 -0
- data/lib/resque/plugins/heroku_scaler/tasks.rb +9 -0
- data/lib/resque/plugins/heroku_scaler/version.rb +7 -0
- data/lib/resque/plugins/{resque_heroku_scaler → heroku_scaler}/worker.rb +0 -0
- data/test/config_test.rb +1 -1
- data/test/{resque_heroku_scaler_test.rb → heroku_scaler_test.rb} +4 -4
- data/test/test_helper.rb +1 -1
- metadata +14 -14
- data/lib/resque/plugins/resque-heroku-scaler.rb +0 -6
- data/lib/resque/plugins/resque_heroku_scaler/tasks.rb +0 -11
- data/lib/resque/plugins/resque_heroku_scaler/version.rb +0 -7
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Resque Heroku Scaler
|
2
2
|
====================
|
3
3
|
|
4
|
-
|
5
|
-
previous scaling work developed by [Daniel Huckstep][dh] and
|
4
|
+
This [gem][rg] provides autoscaling for [Resque][rq] workers on [Heroku][hk].
|
5
|
+
Based on previous scaling work developed by [Daniel Huckstep][dh] and
|
6
6
|
[Alexander Murmann][am].
|
7
7
|
|
8
8
|
Autoscaling behavior is provided through a separate monitor process. The
|
@@ -10,7 +10,14 @@ scaler monitor process polls for pending jobs against the specified Resque
|
|
10
10
|
Redis backend at a configurable interval. The scaler process runs as a worker
|
11
11
|
process on Heroku.
|
12
12
|
|
13
|
-
|
13
|
+
Blog Post
|
14
|
+
---------
|
15
|
+
|
16
|
+
For details on the motivation behind using a separate scaler process, please
|
17
|
+
see [this post][ad].
|
18
|
+
|
19
|
+
Setup
|
20
|
+
-----
|
14
21
|
|
15
22
|
Add the following environment variables to your Heroku environment:
|
16
23
|
|
@@ -18,10 +25,19 @@ Add the following environment variables to your Heroku environment:
|
|
18
25
|
* HEROKU_USERNAME
|
19
26
|
* HEROKU_PASSWORD
|
20
27
|
|
28
|
+
Include the scaler tasks in a file within lib/tasks (ex: lib/tasks/scaler.rake)
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'resque/tasks'
|
32
|
+
require 'resque/plugins/heroku_scaler/tasks'
|
33
|
+
|
34
|
+
task "resque:setup" => :environment
|
35
|
+
```
|
36
|
+
|
21
37
|
In your Procfile, configure the scaler as a worker process using:
|
22
38
|
|
23
39
|
```
|
24
|
-
scaler: bundle exec rake resque:
|
40
|
+
scaler: bundle exec rake resque:heroku_scaler
|
25
41
|
```
|
26
42
|
|
27
43
|
To run the scaler process, use the following command. Note, the scaler process
|
@@ -31,22 +47,40 @@ is intended to run as a single instance.
|
|
31
47
|
heroku scale scaler=1
|
32
48
|
```
|
33
49
|
|
50
|
+
Require the worker extensions within the app running the workers. For example,
|
51
|
+
in lib/tasks/resque.rake.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'resque/tasks'
|
55
|
+
|
56
|
+
task "resque:setup" => :environment do
|
57
|
+
require 'resque-heroku-scaler'
|
58
|
+
ENV['QUEUE'] = '*'
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
34
62
|
In your development environment, the scaler process can run local worker
|
35
|
-
processes using the rush library. To configure,
|
36
|
-
|
63
|
+
processes using the rush library. To configure, update your scaler file in
|
64
|
+
lib/tasks to use the local scale manager below (ex: lib/tasks/scaler.rake).
|
37
65
|
|
38
66
|
```ruby
|
39
|
-
require 'resque/
|
67
|
+
require 'resque/tasks'
|
68
|
+
require 'resque/plugins/heroku_scaler/tasks'
|
40
69
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
70
|
+
task "resque:setup" => :environment do
|
71
|
+
if Rails.env.development?
|
72
|
+
require 'resque-heroku-scaler'
|
73
|
+
ENV["RUSH_PATH"] ||= File.expand_path('/path/to/app', __FILE__)
|
74
|
+
Resque::Plugins::HerokuScaler.configure do |c|
|
75
|
+
c.scale_manager = :local
|
76
|
+
end
|
45
77
|
end
|
46
78
|
end
|
47
79
|
```
|
48
80
|
|
81
|
+
[rg]: http://rubygems.org/gems/resque-heroku-scaler
|
49
82
|
[rq]: http://github.com/defunkt/resque
|
50
83
|
[hk]: http://devcenter.heroku.com/articles/cedar
|
51
84
|
[dh]: http://verboselogging.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
|
52
|
-
[am]:
|
85
|
+
[am]: http://github.com/ajmurmann/resque-heroku-autoscaler
|
86
|
+
[ad]: http://www.dunnington.net/entry/autoscale-resque-workers-on-heroku
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'resque/plugins/heroku_scaler'
|
@@ -1,7 +1,14 @@
|
|
1
|
+
require 'resque'
|
2
|
+
require 'resque/plugins/heroku_scaler/version'
|
3
|
+
require 'resque/plugins/heroku_scaler/config'
|
4
|
+
require 'resque/plugins/heroku_scaler/manager'
|
5
|
+
require 'resque/plugins/heroku_scaler/worker'
|
6
|
+
require 'resque/plugins/heroku_scaler/resque'
|
7
|
+
|
1
8
|
module Resque
|
2
9
|
module Plugins
|
3
10
|
|
4
|
-
module
|
11
|
+
module HerokuScaler
|
5
12
|
class << self
|
6
13
|
|
7
14
|
def run
|
@@ -39,23 +46,23 @@ module Resque
|
|
39
46
|
end
|
40
47
|
|
41
48
|
def wait_for_scale
|
42
|
-
sleep Resque::Plugins::
|
49
|
+
sleep Resque::Plugins::HerokuScaler::Config.scale_interval
|
43
50
|
end
|
44
51
|
|
45
52
|
def wait_for_workers
|
46
|
-
sleep Resque::Plugins::
|
53
|
+
sleep Resque::Plugins::HerokuScaler::Config.poll_interval
|
47
54
|
end
|
48
55
|
|
49
56
|
def scale_for(pending)
|
50
|
-
Resque::Plugins::
|
57
|
+
Resque::Plugins::HerokuScaler::Config.scale_for(pending)
|
51
58
|
end
|
52
59
|
|
53
60
|
def scale_workers(qty)
|
54
|
-
Resque::Plugins::
|
61
|
+
Resque::Plugins::HerokuScaler::Manager.workers = qty
|
55
62
|
end
|
56
63
|
|
57
64
|
def workers
|
58
|
-
Resque::Plugins::
|
65
|
+
Resque::Plugins::HerokuScaler::Manager.workers
|
59
66
|
end
|
60
67
|
|
61
68
|
def signal_workers
|
@@ -71,7 +78,7 @@ module Resque
|
|
71
78
|
end
|
72
79
|
|
73
80
|
def timeout
|
74
|
-
Time.now + Resque::Plugins::
|
81
|
+
Time.now + Resque::Plugins::HerokuScaler::Config.scale_timeout
|
75
82
|
end
|
76
83
|
|
77
84
|
def pending
|
@@ -83,7 +90,7 @@ module Resque
|
|
83
90
|
end
|
84
91
|
|
85
92
|
def configure
|
86
|
-
yield Resque::Plugins::
|
93
|
+
yield Resque::Plugins::HerokuScaler::Config
|
87
94
|
end
|
88
95
|
|
89
96
|
def startup
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Resque
|
2
2
|
module Plugins
|
3
|
-
module
|
3
|
+
module HerokuScaler
|
4
4
|
module Manager
|
5
5
|
extend self
|
6
6
|
|
@@ -9,7 +9,7 @@ module Resque
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def init_manager
|
12
|
-
handler = Resque::Plugins::
|
12
|
+
handler = Resque::Plugins::HerokuScaler::Config.scale_manager
|
13
13
|
return handler unless [Symbol, Array, String].include? handler.class
|
14
14
|
|
15
15
|
options = {}
|
File without changes
|
File without changes
|
data/test/config_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class HerokuScalerTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@scaler = Resque::Plugins::
|
6
|
-
@config = Resque::Plugins::
|
5
|
+
@scaler = Resque::Plugins::HerokuScaler
|
6
|
+
@config = Resque::Plugins::HerokuScaler::Config
|
7
7
|
|
8
8
|
@redis = mock('Mock Redis')
|
9
9
|
@redis.stubs(:set).with(:scale, true).returns(true)
|
@@ -11,7 +11,7 @@ class ResqueHerokuScalerTest < MiniTest::Unit::TestCase
|
|
11
11
|
Resque.stubs(:redis).returns(@redis)
|
12
12
|
|
13
13
|
@manager = mock('Mock Manager')
|
14
|
-
Resque::Plugins::
|
14
|
+
Resque::Plugins::HerokuScaler::Manager.stubs(:instance).returns(@manager)
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_no_scale_for_zero_jobs
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: resque-heroku-scaler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Aaron Dunnington
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-28 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
version: 2.14.0
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
|
-
description: " This gem provides autoscaling
|
38
|
+
description: " This gem provides autoscaling for Resque workers on Heroku.\n"
|
39
39
|
email: spirogh@gmail.com
|
40
40
|
executables: []
|
41
41
|
|
@@ -48,18 +48,18 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- LICENSE
|
50
50
|
- HISTORY.md
|
51
|
-
- lib/resque/plugins/
|
52
|
-
- lib/resque/plugins/
|
53
|
-
- lib/resque/plugins/
|
54
|
-
- lib/resque/plugins/
|
55
|
-
- lib/resque/plugins/
|
56
|
-
- lib/resque/plugins/
|
57
|
-
- lib/resque/plugins/
|
58
|
-
- lib/resque/plugins/
|
59
|
-
- lib/resque/plugins/
|
60
|
-
- lib/resque
|
51
|
+
- lib/resque/plugins/heroku_scaler/config.rb
|
52
|
+
- lib/resque/plugins/heroku_scaler/manager/heroku.rb
|
53
|
+
- lib/resque/plugins/heroku_scaler/manager/local.rb
|
54
|
+
- lib/resque/plugins/heroku_scaler/manager.rb
|
55
|
+
- lib/resque/plugins/heroku_scaler/resque.rb
|
56
|
+
- lib/resque/plugins/heroku_scaler/tasks.rb
|
57
|
+
- lib/resque/plugins/heroku_scaler/version.rb
|
58
|
+
- lib/resque/plugins/heroku_scaler/worker.rb
|
59
|
+
- lib/resque/plugins/heroku_scaler.rb
|
60
|
+
- lib/resque-heroku-scaler.rb
|
61
61
|
- test/config_test.rb
|
62
|
-
- test/
|
62
|
+
- test/heroku_scaler_test.rb
|
63
63
|
- test/test_helper.rb
|
64
64
|
- test/worker_test.rb
|
65
65
|
has_rdoc: true
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require 'resque/plugins/resque_heroku_scaler/version'
|
2
|
-
require 'resque/plugins/resque_heroku_scaler/config'
|
3
|
-
require 'resque/plugins/resque_heroku_scaler/manager'
|
4
|
-
require 'resque/plugins/resque_heroku_scaler/worker'
|
5
|
-
require 'resque/plugins/resque_heroku_scaler/resque'
|
6
|
-
require 'resque/plugins/resque_heroku_scaler'
|