middle_management 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,14 +4,15 @@ require 'delayed/backend/active_record'
|
|
4
4
|
|
5
5
|
module MiddleManagement
|
6
6
|
class Manager
|
7
|
-
|
7
|
+
# ToDo: Figure out what to do about caching worker counts
|
8
|
+
def self.enforce_number_of_current_jobs(_num_workers_last_set_at = nil, _last_enforcement_job_set_for = nil)
|
9
|
+
self.current_worker_count = self.get_heroku_client.info[:workers]
|
8
10
|
# Do nothing if our worker figures are up-to-date
|
9
11
|
return if !self.num_jobs_changes_worker_count?(self.current_jobs_count)
|
10
12
|
|
11
13
|
# Load cached values if they're supplied. This is to prevent different instances
|
12
14
|
# from re-querying the heroku API.
|
13
15
|
self.num_workers_last_set_at = _num_workers_last_set_at unless _num_workers_last_set_at.nil?
|
14
|
-
self.current_worker_count = _current_worker_count unless _current_worker_count.nil?
|
15
16
|
self.last_enforcement_job_set_for = _last_enforcement_job_set_for unless _last_enforcement_job_set_for.nil?
|
16
17
|
|
17
18
|
# Set number of workers if we haven't set it recently
|
@@ -22,7 +23,7 @@ module MiddleManagement
|
|
22
23
|
# Schedule job with cached data if we don't have one scheduled
|
23
24
|
if self.last_enforcement_job_set_for.nil? || Time.now > self.last_enforcement_job_set_for # Prevent multiple jobs within our window
|
24
25
|
self.last_enforcement_job_set_for = Time.now + 10.seconds
|
25
|
-
self.delay(:run_at => self.last_enforcement_job_set_for).enforce_number_of_current_jobs(self.num_workers_last_set_at, self.
|
26
|
+
self.delay(:run_at => self.last_enforcement_job_set_for).enforce_number_of_current_jobs(self.num_workers_last_set_at, self.last_enforcement_job_set_for)
|
26
27
|
# Make sure we have at least one worker running to cover the job.
|
27
28
|
self.set_num_workers(1) if self.current_worker_count == 0
|
28
29
|
end
|
@@ -73,8 +74,8 @@ module MiddleManagement
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def self.set_num_workers(num_workers)
|
76
|
-
self.get_heroku_client.set_workers(MiddleManagement::Config::HEROKU_APP, num_workers)
|
77
77
|
self.current_worker_count = num_workers
|
78
|
+
self.get_heroku_client.set_workers(MiddleManagement::Config::HEROKU_APP, num_workers)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
@@ -24,7 +24,9 @@ describe MiddleManagement::Manager do
|
|
24
24
|
stub_config(:HEROKU_APP, "test_app")
|
25
25
|
stub_config(:MIN_WORKERS, 1)
|
26
26
|
stub_config(:MAX_WORKERS, 10)
|
27
|
+
stub_config(:JOBS_PER_WORKER, 1)
|
27
28
|
@client_mock = mock("Heroku Client")
|
29
|
+
@client_mock.should_receive(:info).any_number_of_times.and_return({:workers => 5})
|
28
30
|
MiddleManagement::Manager.should_receive(:get_heroku_client).any_number_of_times.and_return(@client_mock)
|
29
31
|
end
|
30
32
|
describe "second call within 10 seconds" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middle_management
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Robby Grossman
|