autoscaler 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -1
- data/Guardfile +3 -1
- data/README.md +3 -2
- data/lib/autoscaler/sidekiq.rb +22 -9
- data/lib/autoscaler/version.rb +1 -1
- data/spec/autoscaler/sidekiq_spec.rb +14 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.2.1
|
4
|
+
|
5
|
+
- Separate background activity flags to avoid crosstalk between processes
|
6
|
+
- Autoscaler::StubScaler may be used for local testing
|
7
|
+
|
3
8
|
## 0.2.0
|
4
9
|
|
5
10
|
- Raise minimum Sidekiq version to 2.6.1 to take advantage of Stats API
|
@@ -17,6 +22,6 @@
|
|
17
22
|
|
18
23
|
## 0.0.2
|
19
24
|
|
20
|
-
- Loosen Sidekiq version
|
25
|
+
- Loosen Sidekiq version dependency
|
21
26
|
- Add changelog
|
22
27
|
- Add changelog, readme, and examples to gem files list
|
data/Guardfile
CHANGED
@@ -2,9 +2,11 @@ guard 'process', :name => 'redis', :command => 'redis-server spec/redis_test.con
|
|
2
2
|
watch('spec/redis_test.conf')
|
3
3
|
end
|
4
4
|
|
5
|
+
tag = "--tag #{ENV['TAG']}" if ENV['TAG']
|
6
|
+
example = "-e '#{ENV['EXAMPLE']}'" if ENV['EXAMPLE']
|
5
7
|
guard 'rspec',
|
6
8
|
:version => 2,
|
7
|
-
:cli =>
|
9
|
+
:cli => "--color --format d #{tag} #{example}",
|
8
10
|
:bundler => false,
|
9
11
|
:spec_paths => ['spec'] do
|
10
12
|
watch(%r{^spec/.+_spec\.rb$})
|
data/README.md
CHANGED
@@ -8,11 +8,11 @@ Tested on Ruby 1.9.2 and Heroku Cedar stack.
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
gem install
|
11
|
+
gem install autoscaler
|
12
12
|
|
13
13
|
## Getting Started
|
14
14
|
|
15
|
-
This gem uses the [Herkou-Api](https://github.com/heroku/heroku.rb) gem, which requires an API key from Heroku. It will also need the heroku app name. By default, these are specified through environment variables. You can also pass them to
|
15
|
+
This gem uses the [Herkou-Api](https://github.com/heroku/heroku.rb) gem, which requires an API key from Heroku. It will also need the heroku app name. By default, these are specified through environment variables. You can also pass them to HerokuScaler explicitly.
|
16
16
|
|
17
17
|
HEROKU_API_KEY=.....
|
18
18
|
HEROKU_APP=....
|
@@ -38,6 +38,7 @@ Install the middleware in your `Sidekiq.configure_` blocks
|
|
38
38
|
- Workers sleep-loop and are not actually returned to the pool; when a job or timeout happen, they can all release at once.
|
39
39
|
- If you set job-timeouts on your tasks, they will likely trigger on the sleep-loop (see previous).
|
40
40
|
- The retry and schedule lists are considered - if you schedule a long-running task, the process will not scale-down.
|
41
|
+
- If background jobs trigger jobs in other scaled processes, please note you'll need `config.client_middleware` in your `Sidekiq.configure_server` block in order to scale-up.
|
41
42
|
|
42
43
|
### Long Jobs
|
43
44
|
|
data/lib/autoscaler/sidekiq.rb
CHANGED
@@ -33,10 +33,10 @@ module Autoscaler
|
|
33
33
|
|
34
34
|
# Sidekiq middleware api entry point
|
35
35
|
def call(worker, msg, queue)
|
36
|
-
working!
|
36
|
+
working!(queue)
|
37
37
|
yield
|
38
38
|
ensure
|
39
|
-
working!
|
39
|
+
working!(queue)
|
40
40
|
wait_for_task_or_scale
|
41
41
|
end
|
42
42
|
|
@@ -81,21 +81,34 @@ module Autoscaler
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
def working!
|
85
|
-
|
84
|
+
def working!(queue)
|
85
|
+
active_at queue, Time.now
|
86
|
+
end
|
87
|
+
|
88
|
+
# test support
|
89
|
+
def idle!(queue)
|
90
|
+
active_at queue, Time.now - @timeout*2
|
86
91
|
end
|
87
92
|
|
88
93
|
def idle_time
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Time.now - Time.parse(t)
|
93
|
-
}
|
94
|
+
t = last_activity
|
95
|
+
return 0 unless t
|
96
|
+
Time.now - Time.parse(t)
|
94
97
|
end
|
95
98
|
|
96
99
|
def idle?
|
97
100
|
idle_time > @timeout
|
98
101
|
end
|
102
|
+
|
103
|
+
def last_activity
|
104
|
+
::Sidekiq.redis {|c|
|
105
|
+
queue_names.map {|q| c.get('background_activity:'+q)}.compact.max
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def active_at(queue, time)
|
110
|
+
::Sidekiq.redis {|c| c.set('background_activity:'+queue, time)}
|
111
|
+
end
|
99
112
|
end
|
100
113
|
end
|
101
114
|
end
|
data/lib/autoscaler/version.rb
CHANGED
@@ -9,6 +9,11 @@ class Scaler
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
class Autoscaler::Sidekiq::Server
|
13
|
+
public :idle!
|
14
|
+
public :working!
|
15
|
+
end
|
16
|
+
|
12
17
|
describe Autoscaler::Sidekiq do
|
13
18
|
before do
|
14
19
|
@redis = Sidekiq.redis = REDIS
|
@@ -91,6 +96,15 @@ describe Autoscaler::Sidekiq do
|
|
91
96
|
end
|
92
97
|
when_run_should_scale
|
93
98
|
end
|
99
|
+
|
100
|
+
context "when another process is working" do
|
101
|
+
let(:other_process) {cut.new(Scaler.new(0), 10, ['other_queue'])}
|
102
|
+
before do
|
103
|
+
other_process.idle!('other_queue')
|
104
|
+
server.working!('queue')
|
105
|
+
end
|
106
|
+
it {other_process.should be_idle}
|
107
|
+
end
|
94
108
|
end
|
95
109
|
|
96
110
|
describe 'does not scale' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoscaler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sidekiq
|