stormtroopers 0.1.1 → 0.1.2
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/lib/stormtroopers/army.rb +9 -2
- data/lib/stormtroopers/manager.rb +31 -2
- data/lib/stormtroopers/version.rb +1 -1
- metadata +2 -3
data/lib/stormtroopers/army.rb
CHANGED
@@ -16,12 +16,19 @@ module Stormtroopers
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def manage
|
19
|
-
|
20
|
-
if
|
19
|
+
assigned = false
|
20
|
+
if need_more_troops?
|
21
21
|
if trooper = factory.produce
|
22
22
|
run_trooper(trooper)
|
23
|
+
assigned = true
|
23
24
|
end
|
24
25
|
end
|
26
|
+
assigned
|
27
|
+
end
|
28
|
+
|
29
|
+
def need_more_troops?
|
30
|
+
cleanup
|
31
|
+
threads.count < max_threads
|
25
32
|
end
|
26
33
|
|
27
34
|
def run_trooper(trooper)
|
@@ -5,6 +5,16 @@ require 'active_support/core_ext/hash'
|
|
5
5
|
require 'active_support/hash_with_indifferent_access'
|
6
6
|
require_relative "./already_running"
|
7
7
|
|
8
|
+
|
9
|
+
if ENV["DJ_SPEED"] == "ludicrous"
|
10
|
+
# Go to ludicrous speed (http://www.youtube.com/watch?v=mk7VWcuVOf0) by
|
11
|
+
# overriding Delayed::Job#reserve to do the bare minimum to return a job.
|
12
|
+
# This will cause all of our workers to pick up jobs from ANY queue, so use
|
13
|
+
# with caution!
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
8
18
|
module Stormtroopers
|
9
19
|
class Manager
|
10
20
|
include Singleton
|
@@ -19,9 +29,22 @@ module Stormtroopers
|
|
19
29
|
end
|
20
30
|
|
21
31
|
logger.info "Starting"
|
32
|
+
|
33
|
+
if config[:speed] == "ludicrous"
|
34
|
+
logger.info "Ludicrous speed? Sir! we have never gone that fast before, I dont know if the ship can take it! Whats the matter Colonel Sanders? CHICKEN?!"
|
35
|
+
puts "Ludicrous speed? Sir! we have never gone that fast before, I dont know if the ship can take it! Whats the matter Colonel Sanders? CHICKEN?!"
|
36
|
+
Delayed::Backend::Mongoid::Job.class_eval do
|
37
|
+
def self.reserve(worker, max_run_time = Worker.max_run_time)
|
38
|
+
where(failed_at: nil, locked_at: nil).find_and_modify({"$set" => {locked_at: db_time_now, locked_by: worker.name}}, new: true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
22
45
|
while managing? do
|
23
|
-
armies.
|
24
|
-
sleep
|
46
|
+
assigned = armies.map(&:manage)
|
47
|
+
sleep timeout(assigned.include?(true))
|
25
48
|
end
|
26
49
|
|
27
50
|
armies.each(&:finish)
|
@@ -62,6 +85,12 @@ module Stormtroopers
|
|
62
85
|
|
63
86
|
private
|
64
87
|
|
88
|
+
def timeout(busy)
|
89
|
+
@timeout = 0 if @timeout.nil? || busy
|
90
|
+
@timeout += 0.1 if @timeout < 2
|
91
|
+
@timeout
|
92
|
+
end
|
93
|
+
|
65
94
|
class << self
|
66
95
|
def logger(*args)
|
67
96
|
instance.logger(*args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stormtroopers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2012-11-
|
13
|
+
date: 2012-11-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -117,4 +117,3 @@ test_files:
|
|
117
117
|
- spec/stormtroopers/manager_spec.rb
|
118
118
|
- spec/stormtroopers/trooper/delayed_job_spec.rb
|
119
119
|
- spec/stormtroopers/trooper_spec.rb
|
120
|
-
has_rdoc:
|