stormtroopers 0.1.0 → 0.1.1
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 +6 -0
- data/lib/stormtroopers/army.rb +3 -1
- data/lib/stormtroopers/factory.rb +2 -1
- data/lib/stormtroopers/factory/delayed_job.rb +1 -1
- data/lib/stormtroopers/trooper/delayed_job.rb +1 -0
- data/lib/stormtroopers/version.rb +1 -1
- data/spec/stormtroopers/army_spec.rb +2 -2
- data/spec/stormtroopers/factory_spec.rb +8 -0
- data/spec/stormtroopers/trooper/delayed_job_spec.rb +1 -0
- metadata +2 -1
data/README.md
CHANGED
@@ -54,6 +54,12 @@ Each Army can be given a set of options:
|
|
54
54
|
|
55
55
|
You set the Army's Factory with the factory type or class option. When using type this is translated into a builtin class, when using class you can specify the name of whatever class you like (it needs to implement the appropriate interface to be able to work of course, have a look through the source code and specs to figure out what you need to do). Besides specifying the type or class, you can also specify the Factory's name (used for logging purposes), if you don't give the Factory a name then the Army's name is propagated to the Factory. The factory options also include specific settings for the chosen backend, for DelayedJob you can specify the queues that jobs may be picked up from. If you don't specify queues then the factory will pick up jobs from all queues.
|
56
56
|
|
57
|
+
## TODO
|
58
|
+
|
59
|
+
- Daemonization
|
60
|
+
- Other backends
|
61
|
+
- Documentation
|
62
|
+
|
57
63
|
## Contributing
|
58
64
|
|
59
65
|
1. Fork it
|
data/lib/stormtroopers/army.rb
CHANGED
@@ -4,7 +4,9 @@ module Stormtroopers
|
|
4
4
|
|
5
5
|
def initialize(config)
|
6
6
|
@name = config[:name] || factory_class(config).name
|
7
|
-
|
7
|
+
factory_options = HashWithIndifferentAccess.new(config[:factory])
|
8
|
+
factory_options[:name] ||= config[:name]
|
9
|
+
@factory = factory_class(config).new(factory_options)
|
8
10
|
@max_threads = config[:max_threads] || 1
|
9
11
|
@threads = []
|
10
12
|
end
|
@@ -4,7 +4,7 @@ module Stormtroopers
|
|
4
4
|
worker = Delayed::Worker.new(options)
|
5
5
|
worker.name = "rand #{Time.now.utc.to_f} #{rand(1000)}"
|
6
6
|
if job = Delayed::Job.reserve(worker)
|
7
|
-
logger.info("#{
|
7
|
+
logger.info("#{self.name} producing trooper to run #{job.queue} job #{job.id}")
|
8
8
|
DelayedJobTrooper.new(job)
|
9
9
|
end
|
10
10
|
end
|
@@ -18,7 +18,7 @@ describe Stormtroopers::Army do
|
|
18
18
|
factory_class = stub
|
19
19
|
Stormtroopers::Army.any_instance.should_receive(:factory_class).and_return(factory_class)
|
20
20
|
factory_instance = stub
|
21
|
-
factory_class.should_receive(:new).with(name
|
21
|
+
factory_class.should_receive(:new).with("name" => "Dad's Factory", "type" => :dummy).and_return(factory_instance)
|
22
22
|
army.factory.should equal(factory_instance)
|
23
23
|
end
|
24
24
|
|
@@ -26,7 +26,7 @@ describe Stormtroopers::Army do
|
|
26
26
|
factory_class = stub
|
27
27
|
Stormtroopers::Army.any_instance.should_receive(:factory_class).and_return(factory_class)
|
28
28
|
factory_instance = stub
|
29
|
-
factory_class.should_receive(:new).with(name
|
29
|
+
factory_class.should_receive(:new).with("name" => "Dad's Army", "type" => :dummy).and_return(factory_instance)
|
30
30
|
army = Stormtroopers::Army.new(name: "Dad's Army", max_threads: 2, factory: {type: :dummy})
|
31
31
|
army.factory.should equal(factory_instance)
|
32
32
|
end
|
@@ -9,6 +9,14 @@ describe Stormtroopers::Factory do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
describe "#name" do
|
13
|
+
it "returns name extracted from the options during #initialize" do
|
14
|
+
options = {name: "The Fun Factory"}
|
15
|
+
factory = Stormtroopers::Factory.new(options)
|
16
|
+
factory.name.should eq("The Fun Factory")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
describe "#produce" do
|
13
21
|
it "is not implemented" do
|
14
22
|
factory = Stormtroopers::Factory.new
|
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.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -117,3 +117,4 @@ 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:
|