stormtroopers 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -4,7 +4,9 @@ module Stormtroopers
4
4
 
5
5
  def initialize(config)
6
6
  @name = config[:name] || factory_class(config).name
7
- @factory = factory_class(config).new({name: config[:name]}.merge(config[:factory]))
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
@@ -1,9 +1,10 @@
1
1
  module Stormtroopers
2
2
  class Factory
3
- attr_reader :options
3
+ attr_reader :options, :name
4
4
 
5
5
  def initialize(options = {})
6
6
  @options = options
7
+ @name = options[:name]
7
8
  end
8
9
 
9
10
  def produce
@@ -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("#{options[:name]} producing trooper to run #{job.queue} job #{job.id}")
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
@@ -23,6 +23,7 @@ module Stormtroopers
23
23
  else
24
24
  logger.error("PERMANENTLY removing #{job.name} because of #{job.attempts} consecutive failures.")
25
25
  job.hook(:failure)
26
+ job.fail!
26
27
  end
27
28
  end
28
29
 
@@ -1,3 +1,3 @@
1
1
  module Stormtroopers
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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: "Dad's Factory", type: :dummy).and_return(factory_instance)
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: "Dad's Army", type: :dummy).and_return(factory_instance)
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
@@ -49,6 +49,7 @@ describe Stormtroopers::DelayedJobTrooper do
49
49
  job.stub(:attempts).and_return(3)
50
50
  job.stub(:max_attempts).and_return(3)
51
51
  job.should_receive(:hook).with(:failure)
52
+ job.should_receive(:fail!)
52
53
  trooper.reschedule
53
54
  end
54
55
  end
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.0
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: