workless 1.1.2 → 1.1.3
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 +4 -3
- data/lib/workless/initialize.rb +1 -0
- data/lib/workless/scaler.rb +12 -4
- data/lib/workless/scalers/heroku.rb +1 -1
- data/lib/workless/scalers/heroku_cedar.rb +2 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -9,6 +9,7 @@ By adding the gem to your project and configuring our Heroku app with some confi
|
|
9
9
|
|
10
10
|
## Updates
|
11
11
|
|
12
|
+
* Version 1.1.3 includes changes by @radanskoric to reduce number of heroku api calls
|
12
13
|
* Version 1.1.2 includes a change by @davidakachaos to scale workers using after_commit
|
13
14
|
* Version 1.1.1 includes a fix from @filiptepper and @fixr to correctly scale workers
|
14
15
|
* Version 1.1.0 has been released, this adds support for scaling using multiple workers thanks to @jaimeiniesta and @davidakachaos.
|
@@ -32,21 +33,21 @@ Add the workless gem and the delayed_job gem to your project Gemfile and update
|
|
32
33
|
|
33
34
|
<pre>
|
34
35
|
gem "delayed_job", "2.0.7"
|
35
|
-
gem "workless", "~> 1.1.
|
36
|
+
gem "workless", "~> 1.1.3"
|
36
37
|
</pre>
|
37
38
|
|
38
39
|
### For rails 3.x with delayed_job 2.1.x
|
39
40
|
|
40
41
|
<pre>
|
41
42
|
gem "delayed_job", "~> 2.1.4"
|
42
|
-
gem "workless", "~> 1.1.
|
43
|
+
gem "workless", "~> 1.1.3"
|
43
44
|
</pre>
|
44
45
|
|
45
46
|
### For rails 3.x with latest delayed_job 3.x using active record
|
46
47
|
|
47
48
|
<pre>
|
48
49
|
gem "delayed_job_active_record"
|
49
|
-
gem "workless", "~> 1.1.
|
50
|
+
gem "workless", "~> 1.1.3"
|
50
51
|
</pre>
|
51
52
|
|
52
53
|
If you don't specify delayed_job in your Gemfile workless will bring it in, most likly the latest version (3.0.1)
|
data/lib/workless/initialize.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
Delayed::Worker.max_attempts = 3
|
2
2
|
Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::ActiveRecord::Job)
|
3
3
|
Delayed::Backend::Mongoid::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::Mongoid::Job)
|
4
|
+
Delayed::Backend::MongoMapper::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::MongoMapper::Job)
|
data/lib/workless/scaler.rb
CHANGED
@@ -9,10 +9,18 @@ module Delayed
|
|
9
9
|
|
10
10
|
def self.included(base)
|
11
11
|
base.send :extend, ClassMethods
|
12
|
-
base.
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
unless base.to_s =~ /ActiveRecord/
|
13
|
+
base.class_eval do
|
14
|
+
after_destroy "self.class.scaler.down"
|
15
|
+
after_create "self.class.scaler.up"
|
16
|
+
after_update "self.class.scaler.down", :unless => Proc.new {|r| r.failed_at.nil? }
|
17
|
+
end
|
18
|
+
else
|
19
|
+
base.class_eval do
|
20
|
+
after_commit "self.class.scaler.down", :on => :destroy
|
21
|
+
after_commit "self.class.scaler.up", :on => :create
|
22
|
+
after_commit "self.class.scaler.down", :on => :update, :unless => Proc.new {|r| r.failed_at.nil? }
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
end
|
@@ -7,11 +7,11 @@ module Delayed
|
|
7
7
|
extend Delayed::Workless::Scaler::HerokuClient
|
8
8
|
|
9
9
|
def self.up
|
10
|
-
client.post_ps_scale(ENV['APP_NAME'], 'worker', self.workers_needed) if self.workers < self.workers_needed
|
10
|
+
client.post_ps_scale(ENV['APP_NAME'], 'worker', self.workers_needed) if self.workers_needed > self.min_workers and self.workers < self.workers_needed
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.down
|
14
|
-
client.post_ps_scale(ENV['APP_NAME'], 'worker', self.min_workers) unless self.
|
14
|
+
client.post_ps_scale(ENV['APP_NAME'], 'worker', self.min_workers) unless self.jobs.count > 0 or self.workers == self.min_workers
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.workers
|