hirefire 0.1.3 → 0.1.4
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/CHANGELOG.md +29 -0
- data/README.md +12 -0
- data/Rakefile +12 -0
- data/hirefire.gemspec +3 -2
- data/lib/hirefire.rb +42 -84
- data/lib/hirefire/backend.rb +2 -0
- data/lib/hirefire/backend/delayed_job.rb +11 -0
- data/lib/hirefire/backend/resque.rb +9 -0
- data/lib/hirefire/environment.rb +4 -0
- data/lib/hirefire/environment/base.rb +5 -1
- data/lib/hirefire/initializer.rb +2 -2
- data/lib/hirefire/railtie.rb +1 -1
- data/lib/hirefire/version.rb +1 -1
- data/lib/hirefire/workers.rb +8 -0
- data/lib/hirefire/workers/delayed_job/worker.rb +1 -2
- data/lib/hirefire/workers/resque/worker.rb +3 -4
- data/spec/environment_spec.rb +120 -102
- data/spec/spec_helper.rb +6 -6
- data/spec/support/configuration_helper.rb +33 -0
- metadata +13 -6
data/CHANGELOG.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
0.1.3 / 2011-05-01
|
2
|
+
|
3
|
+
[full changelog](https://github.com/meskyanichi/hirefire/compare/0.1.2...0.1.3)
|
4
|
+
|
5
|
+
* Enhancements
|
6
|
+
* Bumps Heroku gem requirement to ~> 2.0
|
7
|
+
|
8
|
+
0.1.2 / 2011-05-01
|
9
|
+
|
10
|
+
[full changelog](https://github.com/meskyanichi/hirefire/compare/0.1.1...0.1.2)
|
11
|
+
|
12
|
+
* Enhancements
|
13
|
+
* Add min_workers option (Sam Oliver)
|
14
|
+
* Gracefully handle RestClient exceptions (Nathaniel Bibler)
|
15
|
+
* Add Rails 2 compatibility (Estanislau Trepat)
|
16
|
+
* Performance improvements
|
17
|
+
|
18
|
+
0.1.1 / 2011-04-15
|
19
|
+
|
20
|
+
[full changelog](https://github.com/meskyanichi/hirefire/compare/0.1.0...0.1.1)
|
21
|
+
|
22
|
+
* Enhancements
|
23
|
+
* Add support for Resque workers
|
24
|
+
* Add functional job/worker ratio definition option (Dirk Gadsden)
|
25
|
+
* Improve overall performance
|
26
|
+
|
27
|
+
0.1.0 / 2011-04-10
|
28
|
+
|
29
|
+
* Initial release.
|
data/README.md
CHANGED
@@ -17,6 +17,18 @@ Author
|
|
17
17
|
Drop me a message for any questions, suggestions, requests, bugs or submit them to the [issue log](https://github.com/meskyanichi/hirefire/issues).
|
18
18
|
|
19
19
|
|
20
|
+
HireFireApp.com - The Heroku Worker Manager - BETA
|
21
|
+
--------------------------------------------------
|
22
|
+
|
23
|
+
*This is not part of the "HireFire open source" project, but it could potentially help support my open source projects!*
|
24
|
+
|
25
|
+
I would like to announce the release of a **new service** I've been working on, called **HireFireApp**. The goal is essentially the same as the open source HireFire project, except that it's considered more **stable/reliable** and **a lot more performant**.
|
26
|
+
|
27
|
+
The service is currently in beta, so feel free to create a free account and try it out!
|
28
|
+
|
29
|
+
Check out the [official website](http://hirefireapp.com) for more information: [http://hirefireapp.com](http://hirefireapp.com)
|
30
|
+
|
31
|
+
|
20
32
|
Setting it up
|
21
33
|
-------------
|
22
34
|
|
data/Rakefile
ADDED
data/hirefire.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
$:.push File.expand_path('../lib', __FILE__)
|
4
|
+
require 'hirefire/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |gem|
|
6
7
|
|
@@ -23,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
23
24
|
|
24
25
|
##
|
25
26
|
# Production gem dependencies
|
26
|
-
gem.add_dependency 'heroku', ['
|
27
|
+
gem.add_dependency 'heroku', ['>= 1.4']
|
27
28
|
gem.add_dependency 'rush', ['~> 0.6.7']
|
28
29
|
|
29
30
|
end
|
data/lib/hirefire.rb
CHANGED
@@ -1,98 +1,56 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module HireFire
|
4
|
+
autoload :Configuration, 'hirefire/configuration'
|
5
|
+
autoload :Environment, 'hirefire/environment'
|
6
|
+
autoload :Initializer, 'hirefire/initializer'
|
7
|
+
autoload :Backend, 'hirefire/backend'
|
8
|
+
autoload :Logger, 'hirefire/logger'
|
9
|
+
autoload :Version, 'hirefire/version'
|
4
10
|
|
5
|
-
|
6
|
-
# HireFire constants
|
7
|
-
LIB_PATH = File.dirname(__FILE__)
|
8
|
-
HIREFIRE_PATH = File.join(LIB_PATH, 'hirefire')
|
9
|
-
ENVIRONMENT_PATH = File.join(HIREFIRE_PATH, 'environment')
|
10
|
-
BACKEND_PATH = File.join(HIREFIRE_PATH, 'backend')
|
11
|
-
WORKERS_PATH = File.join(HIREFIRE_PATH, 'workers')
|
11
|
+
class << self
|
12
12
|
|
13
|
-
|
14
|
-
# HireFire namespace
|
15
|
-
autoload :Configuration, File.join(HIREFIRE_PATH, 'configuration')
|
16
|
-
autoload :Environment, File.join(HIREFIRE_PATH, 'environment')
|
17
|
-
autoload :Initializer, File.join(HIREFIRE_PATH, 'initializer')
|
18
|
-
autoload :Backend, File.join(HIREFIRE_PATH, 'backend')
|
19
|
-
autoload :Logger, File.join(HIREFIRE_PATH, 'logger')
|
20
|
-
autoload :Version, File.join(HIREFIRE_PATH, 'version')
|
21
|
-
|
22
|
-
##
|
23
|
-
# HireFire::Environment namespace
|
24
|
-
module Environment
|
25
|
-
autoload :Base, File.join(ENVIRONMENT_PATH, 'base')
|
26
|
-
autoload :Heroku, File.join(ENVIRONMENT_PATH, 'heroku')
|
27
|
-
autoload :Local, File.join(ENVIRONMENT_PATH, 'local')
|
28
|
-
autoload :Noop, File.join(ENVIRONMENT_PATH, 'noop')
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# HireFire::Workers namespace
|
33
|
-
module Workers
|
34
|
-
autoload :DelayedJob, File.join(WORKERS_PATH, 'delayed_job')
|
35
|
-
autoload :Resque, File.join(WORKERS_PATH, 'resque')
|
36
|
-
end
|
37
|
-
|
38
|
-
##
|
39
|
-
# HireFire::Backend namespace
|
40
|
-
module Backend
|
41
|
-
DELAYED_JOB_PATH = File.join(BACKEND_PATH, 'delayed_job')
|
42
|
-
RESQUE_PATH = File.join(BACKEND_PATH, 'resque')
|
13
|
+
attr_writer :configuration
|
43
14
|
|
44
15
|
##
|
45
|
-
# HireFire
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
16
|
+
# This method is used to configure HireFire
|
17
|
+
#
|
18
|
+
# @yield [config] the instance of HireFire::Configuration class
|
19
|
+
# @yieldparam [Fixnum] max_workers default: 1 (set at least 1)
|
20
|
+
# @yieldparam [Array] job_worker_ratio default: see example
|
21
|
+
# @yieldparam [Symbol, nil] environment (:heroku, :local, :noop or nil) - default: nil
|
22
|
+
#
|
23
|
+
# @note Every param has it's own defaults. It's best to leave the environment param at "nil".
|
24
|
+
# When environment is set to "nil", it'll default to the :noop environment. This basically means
|
25
|
+
# that you have to run "rake jobs:work" yourself from the console to get the jobs running in development mode.
|
26
|
+
# In production, it'll automatically use :heroku if deployed to the Heroku platform.
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# HireFire.configure do |config|
|
30
|
+
# config.environment = nil
|
31
|
+
# config.max_workers = 5
|
32
|
+
# config.min_workers = 0
|
33
|
+
# config.job_worker_ratio = [
|
34
|
+
# { :jobs => 1, :workers => 1 },
|
35
|
+
# { :jobs => 15, :workers => 2 },
|
36
|
+
# { :jobs => 35, :workers => 3 },
|
37
|
+
# { :jobs => 60, :workers => 4 },
|
38
|
+
# { :jobs => 80, :workers => 5 }
|
39
|
+
# ]
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# @return [nil]
|
43
|
+
def configure
|
44
|
+
yield(configuration); nil
|
50
45
|
end
|
51
46
|
|
52
47
|
##
|
53
|
-
# HireFire::
|
54
|
-
|
55
|
-
|
48
|
+
# Instantiates a new HireFire::Configuration
|
49
|
+
# instance and instance variable caches it
|
50
|
+
def configuration
|
51
|
+
@configuration ||= HireFire::Configuration.new
|
56
52
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# This method is used to configure HireFire
|
61
|
-
#
|
62
|
-
# @yield [config] the instance of HireFire::Configuration class
|
63
|
-
# @yieldparam [Fixnum] max_workers default: 1 (set at least 1)
|
64
|
-
# @yieldparam [Array] job_worker_ratio default: see example
|
65
|
-
# @yieldparam [Symbol, nil] environment (:heroku, :local, :noop or nil) - default: nil
|
66
|
-
#
|
67
|
-
# @note Every param has it's own defaults. It's best to leave the environment param at "nil".
|
68
|
-
# When environment is set to "nil", it'll default to the :noop environment. This basically means
|
69
|
-
# that you have to run "rake jobs:work" yourself from the console to get the jobs running in development mode.
|
70
|
-
# In production, it'll automatically use :heroku if deployed to the Heroku platform.
|
71
|
-
#
|
72
|
-
# @example
|
73
|
-
# HireFire.configure do |config|
|
74
|
-
# config.environment = nil
|
75
|
-
# config.max_workers = 5
|
76
|
-
# config.min_workers = 0
|
77
|
-
# config.job_worker_ratio = [
|
78
|
-
# { :jobs => 1, :workers => 1 },
|
79
|
-
# { :jobs => 15, :workers => 2 },
|
80
|
-
# { :jobs => 35, :workers => 3 },
|
81
|
-
# { :jobs => 60, :workers => 4 },
|
82
|
-
# { :jobs => 80, :workers => 5 }
|
83
|
-
# ]
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# @return [nil]
|
87
|
-
def self.configure
|
88
|
-
yield(configuration); nil
|
89
|
-
end
|
90
53
|
|
91
|
-
##
|
92
|
-
# Instantiates a new HireFire::Configuration
|
93
|
-
# instance and instance variable caches it
|
94
|
-
def self.configuration
|
95
|
-
@configuration ||= HireFire::Configuration.new
|
96
54
|
end
|
97
55
|
|
98
56
|
end
|
@@ -106,7 +64,7 @@ end
|
|
106
64
|
# and the desired mapper (ActiveRecord, Mongoid or Redis)
|
107
65
|
if defined?(Rails)
|
108
66
|
if defined?(Rails::Railtie)
|
109
|
-
require
|
67
|
+
require 'hirefire/railtie'
|
110
68
|
else
|
111
69
|
HireFire::Initializer.initialize!
|
112
70
|
end
|
data/lib/hirefire/backend.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module HireFire
|
4
|
+
module Backend
|
5
|
+
module DelayedJob
|
6
|
+
autoload :ActiveRecord, 'hirefire/backend/delayed_job/active_record'
|
7
|
+
autoload :ActiveRecord2, 'hirefire/backend/delayed_job/active_record_2'
|
8
|
+
autoload :Mongoid, 'hirefire/backend/delayed_job/mongoid'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/hirefire/environment.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
module HireFire
|
4
4
|
module Environment
|
5
|
+
autoload :Base, 'hirefire/environment/base'
|
6
|
+
autoload :Heroku, 'hirefire/environment/heroku'
|
7
|
+
autoload :Local, 'hirefire/environment/local'
|
8
|
+
autoload :Noop, 'hirefire/environment/noop'
|
5
9
|
|
6
10
|
##
|
7
11
|
# This module gets included in either:
|
@@ -163,12 +163,16 @@ module HireFire
|
|
163
163
|
# If there are workers active, but there are no more pending jobs,
|
164
164
|
# then fire all the workers or set to the minimum_workers
|
165
165
|
#
|
166
|
-
# @return [
|
166
|
+
# @return [Boolean] if the workers have been fired
|
167
167
|
def fire
|
168
168
|
if jobs == 0 and workers > min_workers
|
169
169
|
Logger.message("All queued jobs have been processed. " + (min_workers > 0 ? "Setting workers to #{min_workers}." : "Firing all workers."))
|
170
170
|
workers(min_workers)
|
171
|
+
|
172
|
+
return true
|
171
173
|
end
|
174
|
+
|
175
|
+
return false
|
172
176
|
end
|
173
177
|
|
174
178
|
private
|
data/lib/hirefire/initializer.rb
CHANGED
@@ -46,7 +46,7 @@ module HireFire
|
|
46
46
|
##
|
47
47
|
# Load Delayed Job extensions, this will patch Delayed::Worker
|
48
48
|
# to implement the necessary hooks to invoke HireFire from
|
49
|
-
require
|
49
|
+
require 'hirefire/workers/delayed_job'
|
50
50
|
end
|
51
51
|
|
52
52
|
##
|
@@ -65,7 +65,7 @@ module HireFire
|
|
65
65
|
##
|
66
66
|
# Load Resque extensions, this will patch Resque, Resque::Job and Resque::Worker
|
67
67
|
# to implement the necessary hooks to invoke HireFire from
|
68
|
-
require
|
68
|
+
require 'hirefire/workers/resque'
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
data/lib/hirefire/railtie.rb
CHANGED
@@ -32,7 +32,7 @@ module HireFire
|
|
32
32
|
# If Resque is loaded, then we load the Resque rake task
|
33
33
|
# that'll allow Heroku to start up Resque as a worker
|
34
34
|
if defined?(::Resque)
|
35
|
-
require
|
35
|
+
require 'hirefire/workers/resque/tasks'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/lib/hirefire/version.rb
CHANGED
@@ -59,8 +59,7 @@ module Delayed
|
|
59
59
|
# If this is the case it'll command the current environment to fire all the hired workers
|
60
60
|
# and then immediately break out of this infinite loop.
|
61
61
|
if queued.jobs == 0
|
62
|
-
Delayed::Job.environment.fire
|
63
|
-
break
|
62
|
+
break if Delayed::Job.environment.fire
|
64
63
|
end
|
65
64
|
|
66
65
|
break if $exit
|
@@ -41,12 +41,11 @@ module ::Resque
|
|
41
41
|
# If this is the case it'll command the current environment to fire all the hired workers
|
42
42
|
# and then immediately break out of this infinite loop.
|
43
43
|
if (::Resque::Job.jobs + ::Resque::Job.working) == 0
|
44
|
-
::Resque::Job.environment.fire
|
45
|
-
break
|
46
|
-
else
|
47
|
-
sleep(interval)
|
44
|
+
break if ::Resque::Job.environment.fire
|
48
45
|
end
|
49
46
|
|
47
|
+
sleep(interval)
|
48
|
+
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
data/spec/environment_spec.rb
CHANGED
@@ -102,27 +102,30 @@ describe HireFire::Environment::Base do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should set the workers to minimum workers when there arent any jobs' do
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
with_min_workers(2) do
|
106
|
+
base.jobs = 0
|
107
|
+
base.workers = 10
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
HireFire::Logger.expects(:message).with('All queued jobs have been processed. Setting workers to 2.')
|
110
|
+
base.expects(:workers).with(2).once
|
111
|
+
base.fire
|
112
|
+
end
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
115
116
|
describe '#hire' do
|
116
117
|
describe 'the standard notation' do
|
117
118
|
before do
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
119
|
+
configure do |config|
|
120
|
+
config.max_workers = 5
|
121
|
+
config.job_worker_ratio = [
|
122
|
+
{ :jobs => 1, :workers => 1 },
|
123
|
+
{ :jobs => 15, :workers => 2 },
|
124
|
+
{ :jobs => 30, :workers => 3 },
|
125
|
+
{ :jobs => 60, :workers => 4 },
|
126
|
+
{ :jobs => 90, :workers => 5 }
|
127
|
+
]
|
128
|
+
end
|
126
129
|
end
|
127
130
|
|
128
131
|
it 'should request 1 worker' do
|
@@ -178,56 +181,62 @@ describe HireFire::Environment::Base do
|
|
178
181
|
end
|
179
182
|
|
180
183
|
it 'should NEVER hire more workers than the #max_workers' do
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
base.stubs(:max_workers).returns(3) # set the max_workers = 3
|
184
|
+
with_max_workers(3) do
|
185
|
+
base.jobs = 100
|
186
|
+
base.workers = 0
|
185
187
|
|
186
|
-
|
187
|
-
|
188
|
-
|
188
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 3 in total.').once
|
189
|
+
base.expects(:workers).with(3).once
|
190
|
+
base.hire
|
191
|
+
end
|
189
192
|
end
|
190
193
|
|
191
194
|
it 'should not hire 5 workers even if defined in the job/ratio, when the limit is 3, it should hire 3 max' do
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
195
|
+
with_configuration do |config|
|
196
|
+
config.max_workers = 3
|
197
|
+
config.job_worker_ratio = [
|
198
|
+
{ :jobs => 5, :workers => 5 }
|
199
|
+
]
|
200
|
+
|
201
|
+
base.jobs = 100
|
202
|
+
base.workers = 0
|
203
|
+
|
204
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 3 in total.').once
|
205
|
+
base.expects(:workers).with(3).once
|
206
|
+
base.hire
|
207
|
+
end
|
203
208
|
end
|
204
209
|
|
205
210
|
it 'should not hire (or invoke) any more workers since the max amount allowed is already running' do
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
211
|
+
with_configuration do |config|
|
212
|
+
config.max_workers = 3
|
213
|
+
config.job_worker_ratio = [
|
214
|
+
{ :jobs => 5, :workers => 5 }
|
215
|
+
]
|
216
|
+
|
217
|
+
base.jobs = 100
|
218
|
+
base.workers = 3
|
219
|
+
|
220
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 3 in total.').never
|
221
|
+
base.expects(:workers).with(3).never
|
222
|
+
base.hire
|
223
|
+
end
|
217
224
|
end
|
218
225
|
|
219
226
|
it 'the max_workers option can only "limit" the amount of max_workers when used in the "Standard Notation"' do
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
227
|
+
with_configuration do |config|
|
228
|
+
config.max_workers = 10
|
229
|
+
config.job_worker_ratio = [
|
230
|
+
{ :jobs => 5, :workers => 5 }
|
231
|
+
]
|
232
|
+
|
233
|
+
base.jobs = 100
|
234
|
+
base.workers = 0
|
235
|
+
|
236
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 5 in total.').once
|
237
|
+
base.expects(:workers).with(5).once
|
238
|
+
base.hire
|
239
|
+
end
|
231
240
|
end
|
232
241
|
|
233
242
|
it 'should NEVER do API requests to Heroku if the max_workers are already running' do
|
@@ -251,13 +260,15 @@ describe HireFire::Environment::Base do
|
|
251
260
|
|
252
261
|
describe 'the Lambda (functional) notation' do
|
253
262
|
before do
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
263
|
+
configure do |config|
|
264
|
+
config.max_workers = 5
|
265
|
+
config.job_worker_ratio = [
|
266
|
+
{ :when => lambda {|jobs| jobs < 15 }, :workers => 1 },
|
267
|
+
{ :when => lambda {|jobs| jobs < 30 }, :workers => 2 },
|
268
|
+
{ :when => lambda {|jobs| jobs < 60 }, :workers => 3 },
|
269
|
+
{ :when => lambda {|jobs| jobs < 90 }, :workers => 4 }
|
270
|
+
]
|
271
|
+
end
|
261
272
|
end
|
262
273
|
|
263
274
|
it 'should request 1 worker' do
|
@@ -313,56 +324,63 @@ describe HireFire::Environment::Base do
|
|
313
324
|
end
|
314
325
|
|
315
326
|
it 'should NEVER hire more workers than the #max_workers' do
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
327
|
+
with_configuration do |config|
|
328
|
+
config.max_workers = 3
|
329
|
+
base.jobs = 100
|
330
|
+
base.workers = 0
|
331
|
+
|
332
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 3 in total.').once
|
333
|
+
base.expects(:workers).with(3).once
|
334
|
+
base.hire
|
335
|
+
end
|
324
336
|
end
|
325
337
|
|
326
338
|
it 'should not hire 5 workers even if defined in the job/ratio, when the limit is 3, it should hire 3 max' do
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
339
|
+
with_configuration do |config|
|
340
|
+
config.max_workers = 3
|
341
|
+
config.job_worker_ratio = [
|
342
|
+
{ :when => lambda { |jobs| jobs < 5 }, :workers => 5 }
|
343
|
+
]
|
344
|
+
|
345
|
+
base.jobs = 100
|
346
|
+
base.workers = 0
|
347
|
+
|
348
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 3 in total.').once
|
349
|
+
base.expects(:workers).with(3).once
|
350
|
+
base.hire
|
351
|
+
end
|
338
352
|
end
|
339
353
|
|
340
354
|
it 'should not hire (or invoke) any more workers since the max amount allowed is already running' do
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
355
|
+
with_configuration do |config|
|
356
|
+
config.max_workers = 3
|
357
|
+
config.job_worker_ratio = [
|
358
|
+
{ :when => lambda { |jobs| jobs < 5 }, :workers => 5 }
|
359
|
+
]
|
360
|
+
|
361
|
+
base.jobs = 100
|
362
|
+
base.workers = 3
|
363
|
+
|
364
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 3 in total.').never
|
365
|
+
base.expects(:workers).with(3).never
|
366
|
+
base.hire
|
367
|
+
end
|
352
368
|
end
|
353
369
|
|
354
370
|
it 'the max_workers option can only "limit" the amount of max_workers when used in the "Standard Notation"' do
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
371
|
+
with_configuration do |config|
|
372
|
+
config.max_workers = 10
|
373
|
+
config.job_worker_ratio = [
|
374
|
+
{ :when => lambda { |jobs| jobs < 5 }, :workers => 5 }
|
375
|
+
]
|
376
|
+
|
377
|
+
base.jobs = 100
|
378
|
+
base.workers = 0
|
379
|
+
|
380
|
+
HireFire::Logger.expects(:message).with('Hiring more workers so we have 10 in total.').once
|
381
|
+
base.expects(:workers).with(10).once
|
382
|
+
base.hire
|
383
|
+
end
|
366
384
|
end
|
367
385
|
|
368
386
|
it 'should NEVER do API requests to Heroku if the max_workers are already running' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
$:.unshift(File.expand_path('../', __FILE__))
|
3
|
+
$:.unshift(File.expand_path('../../lib', __FILE__))
|
2
4
|
|
3
|
-
|
4
|
-
# Path to the lib directory
|
5
|
-
LIB_PATH = File.expand_path('../../lib', __FILE__)
|
5
|
+
require 'hirefire'
|
6
6
|
|
7
|
-
|
8
|
-
#
|
9
|
-
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
Dir[File.join(File.expand_path('../support', __FILE__), '**/*.rb')].each {|f| require f}
|
10
10
|
|
11
11
|
##
|
12
12
|
# Use Mocha to mock with RSpec
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConfigurationHelper
|
4
|
+
def configure(&block)
|
5
|
+
HireFire.configure(&block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def with_configuration(&block)
|
9
|
+
old_configuration = HireFire.configuration
|
10
|
+
HireFire.configuration = HireFire::Configuration.new
|
11
|
+
yield(HireFire.configuration)
|
12
|
+
ensure
|
13
|
+
HireFire.configuration = old_configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_max_workers(workers, &block)
|
17
|
+
with_configuration do |config|
|
18
|
+
config.max_workers = workers
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def with_min_workers(workers, &block)
|
24
|
+
with_configuration do |config|
|
25
|
+
config.min_workers = workers
|
26
|
+
yield
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.include ConfigurationHelper
|
33
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: hirefire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael van Rooijen
|
@@ -10,7 +10,8 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-28 00:00:00 +02:00
|
14
|
+
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: heroku
|
@@ -18,9 +19,9 @@ dependencies:
|
|
18
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
20
|
none: false
|
20
21
|
requirements:
|
21
|
-
- -
|
22
|
+
- - ">="
|
22
23
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
+
version: "1.4"
|
24
25
|
type: :runtime
|
25
26
|
version_requirements: *id001
|
26
27
|
- !ruby/object:Gem::Dependency
|
@@ -47,16 +48,20 @@ files:
|
|
47
48
|
- .gitignore
|
48
49
|
- .infinity_test
|
49
50
|
- .rspec
|
51
|
+
- CHANGELOG.md
|
50
52
|
- Gemfile
|
51
53
|
- Gemfile.lock
|
52
54
|
- LICENSE.md
|
53
55
|
- README.md
|
56
|
+
- Rakefile
|
54
57
|
- hirefire.gemspec
|
55
58
|
- lib/hirefire.rb
|
56
59
|
- lib/hirefire/backend.rb
|
60
|
+
- lib/hirefire/backend/delayed_job.rb
|
57
61
|
- lib/hirefire/backend/delayed_job/active_record.rb
|
58
62
|
- lib/hirefire/backend/delayed_job/active_record_2.rb
|
59
63
|
- lib/hirefire/backend/delayed_job/mongoid.rb
|
64
|
+
- lib/hirefire/backend/resque.rb
|
60
65
|
- lib/hirefire/backend/resque/redis.rb
|
61
66
|
- lib/hirefire/configuration.rb
|
62
67
|
- lib/hirefire/environment.rb
|
@@ -68,6 +73,7 @@ files:
|
|
68
73
|
- lib/hirefire/logger.rb
|
69
74
|
- lib/hirefire/railtie.rb
|
70
75
|
- lib/hirefire/version.rb
|
76
|
+
- lib/hirefire/workers.rb
|
71
77
|
- lib/hirefire/workers/delayed_job.rb
|
72
78
|
- lib/hirefire/workers/delayed_job/worker.rb
|
73
79
|
- lib/hirefire/workers/resque.rb
|
@@ -78,6 +84,8 @@ files:
|
|
78
84
|
- spec/environment_spec.rb
|
79
85
|
- spec/logger_spec.rb
|
80
86
|
- spec/spec_helper.rb
|
87
|
+
- spec/support/configuration_helper.rb
|
88
|
+
has_rdoc: true
|
81
89
|
homepage: http://rubygems.org/gems/hirefire
|
82
90
|
licenses: []
|
83
91
|
|
@@ -101,10 +109,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
109
|
requirements: []
|
102
110
|
|
103
111
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.6.2
|
105
113
|
signing_key:
|
106
114
|
specification_version: 3
|
107
115
|
summary: HireFire automatically "hires" and "fires" (aka "scales") Delayed Job and Resque workers on Heroku.
|
108
116
|
test_files: []
|
109
117
|
|
110
|
-
has_rdoc:
|