howler 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- howler (1.0.0)
4
+ howler (1.1.0)
5
5
  celluloid
6
6
  connection_pool
7
7
  multi_json
@@ -9,11 +9,11 @@ module Howler
9
9
  args.to_s.gsub(/^\[|\]$/, '')
10
10
  end
11
11
  def self.redis
12
- @connection ||= ConnectionPool.new(:timeout => 1, :size => 5) { _redis }
12
+ @connection ||= ConnectionPool.new(:timeout => 1, :size => 30) { _redis }
13
13
  end
14
14
  private
15
- def self._redis
16
- @redis ||= ::Redis.connect(:url => 'redis://localhost:6379/0')
15
+ def self._redis(url = 'redis://localhost:6379/0')
16
+ @redis ||= ::Redis.connect(:url => url, :thread_safe => true)
17
17
  end
18
18
  end
19
19
 
@@ -51,7 +51,7 @@ module Howler
51
51
  end
52
52
 
53
53
  @logger.log do |log|
54
- log.info("Processing #{messages.size} Messages")
54
+ log.info("Processing #{messages.size} Messages") if messages.size > 0
55
55
 
56
56
  sleep(1) unless messages.any?
57
57
 
@@ -1,10 +1,20 @@
1
- Howler::Config[:concurrency] = 1
2
- Howler::Config[:shutdown_timeout] = 5
3
-
4
1
  module Howler
5
2
  class Runner
3
+ attr_reader :options
4
+
5
+ def initialize
6
+ @options = {
7
+ :concurrency => 30,
8
+ :path => './config/environment.rb',
9
+ :shutdown_timeout => 5
10
+ }
11
+
12
+ parse_options
13
+ set_options
14
+ end
15
+
6
16
  def run
7
- require "./config/environment.rb"
17
+ require Howler::Config[:path]
8
18
  @manager = Howler::Manager.current
9
19
 
10
20
  begin
@@ -30,5 +40,42 @@ module Howler
30
40
  logger.info("INT - All workers have shut down - Exiting")
31
41
  end
32
42
  end
43
+
44
+ private
45
+
46
+ def set_options
47
+ Howler._redis @options[:redis_url]
48
+
49
+ @options.each_pair do |option, value|
50
+ Howler::Config[option] = value
51
+ end
52
+ end
53
+
54
+ def parse_options
55
+ OptionParser.new do |opts|
56
+ opts.on('-k', '--key_value OPTIONS', 'Arbitrary key - values into Howler::Config [key:value,another:value]') do |kvs|
57
+ kvs.split(',').each do |kv|
58
+ kv = kv.split(':')
59
+ @options[kv.first] = kv.last
60
+ end
61
+ end
62
+
63
+ opts.on('-r', '--redis_url URL', 'The url of the Redis Server [redis://localhost:6379/0]') do |url|
64
+ @options[:redis_url] = url
65
+ end
66
+
67
+ opts.on('-c', '--concurrency COUNT', 'The number of Workers [30]') do |c|
68
+ @options[:concurrency] = c
69
+ end
70
+
71
+ opts.on('-p', '--path PATH', 'The path to the file to load [./config/environment.rb]') do |path|
72
+ @options[:path] = path
73
+ end
74
+
75
+ opts.on('-s', '--shutdown_timeout SECONDS', 'The number of seconds to wait for workers to finish [5]') do |seconds|
76
+ @options[:shutdown_timeout] = seconds
77
+ end
78
+ end.parse!
79
+ end
33
80
  end
34
81
  end
@@ -1,3 +1,3 @@
1
1
  module Howler
2
- VERSION = %W(1 1 0) .join(".")
2
+ VERSION = %W(1 1 1) .join(".")
3
3
  end
@@ -46,7 +46,7 @@ describe Howler do
46
46
  let(:pool) { mock("ConnectionPool2") }
47
47
 
48
48
  xit "should be a ConnectionPool" do
49
- ConnectionPool.should_receive(:new).with(:timeout => 1, :size => 5)
49
+ ConnectionPool.should_receive(:new).with(:timeout => 1, :size => 30)
50
50
 
51
51
  Howler.redis
52
52
  end
@@ -206,34 +206,46 @@ describe Howler::Manager do
206
206
  subject.wrapped_object.stub(:done?).and_return(false, true)
207
207
  subject.wrapped_object.instance_variable_set(:@logger, logger)
208
208
  logger.stub(:log).and_yield(log)
209
+ end
210
+
211
+ describe "when there are no messages" do
212
+ it "should not log" do
213
+ log.should_not_receive(:info)
209
214
 
210
- [:send_notification, :enforce_avgs].each_with_index do |method, i|
211
- subject.push(Array, method, [i, ((i+1)*100).to_s(36)])
215
+ subject.run
212
216
  end
213
217
  end
214
218
 
215
- describe "information" do
219
+ describe "when there are messages" do
216
220
  before do
217
- Howler::Config[:log] = 'info'
221
+ [:send_notification, :enforce_avgs].each_with_index do |method, i|
222
+ subject.push(Array, method, [i, ((i+1)*100).to_s(36)])
223
+ end
218
224
  end
219
225
 
220
- it "should log the number of messages to be processed" do
221
- log.should_receive(:info).with("Processing 2 Messages")
226
+ describe "information" do
227
+ before do
228
+ Howler::Config[:log] = 'info'
229
+ end
222
230
 
223
- subject.run
224
- end
225
- end
231
+ it "should log the number of messages to be processed" do
232
+ log.should_receive(:info).with("Processing 2 Messages")
226
233
 
227
- describe "debug" do
228
- before do
229
- Howler::Config[:log] = 'debug'
234
+ subject.run
235
+ end
230
236
  end
231
237
 
232
- it "should show a digest of the messages" do
233
- log.should_receive(:debug).with('MESG - 123 Array.new.send_notification(0, "2s")')
234
- log.should_receive(:debug).with('MESG - 123 Array.new.enforce_avgs(1, "5k")')
238
+ describe "debug" do
239
+ before do
240
+ Howler::Config[:log] = 'debug'
241
+ end
235
242
 
236
- subject.run
243
+ it "should show a digest of the messages" do
244
+ log.should_receive(:debug).with('MESG - 123 Array.new.send_notification(0, "2s")')
245
+ log.should_receive(:debug).with('MESG - 123 Array.new.enforce_avgs(1, "5k")')
246
+
247
+ subject.run
248
+ end
237
249
  end
238
250
  end
239
251
  end
@@ -6,6 +6,138 @@ describe Howler::Runner do
6
6
  subject.stub(:sleep)
7
7
  end
8
8
 
9
+ describe ".new" do
10
+ let!(:opts) { mock(OptionParser, :on => nil, :parse! => nil) }
11
+
12
+ describe "parsing options" do
13
+ before do
14
+ OptionParser.stub(:new).and_yield(opts).and_return(opts)
15
+ end
16
+
17
+ it "should set up an options parser" do
18
+ OptionParser.should_receive(:new)
19
+
20
+ Howler::Runner.new
21
+ end
22
+
23
+ it "should parse the options" do
24
+ opts.should_receive(:parse!)
25
+
26
+ Howler::Runner.new
27
+ end
28
+ end
29
+
30
+ describe "for the redis url" do
31
+ before do
32
+ ARGV.replace(['-r', 'anything'])
33
+ end
34
+
35
+ it "should setup the matcher" do
36
+ OptionParser.stub(:new).and_yield(opts).and_return(opts)
37
+ opts.should_receive(:on).with("-r", "--redis_url URL", "The url of the Redis Server [redis://localhost:6379/0]")
38
+
39
+ Howler::Runner.new
40
+ end
41
+
42
+ it "should set the argument" do
43
+ Howler::Runner.new.options[:redis_url].should == 'anything'
44
+ end
45
+ end
46
+
47
+ describe "for custom key - values" do
48
+ before do
49
+ ARGV.replace(['-k', 'key:value,k:5'])
50
+ end
51
+
52
+ it "should setup the matcher" do
53
+ OptionParser.stub(:new).and_yield(opts).and_return(opts)
54
+ opts.should_receive(:on).with("-k", "--key_value OPTIONS", "Arbitrary key - values into Howler::Config [key:value,another:value]")
55
+
56
+ Howler::Runner.new
57
+ end
58
+
59
+ it "should set the argument" do
60
+ runner = Howler::Runner.new
61
+
62
+ runner.options['key'].should == 'value'
63
+ runner.options['k'].should == '5'
64
+ end
65
+ end
66
+
67
+ describe "for concurrency" do
68
+ before do
69
+ ARGV.replace(['-c', '50'])
70
+ end
71
+
72
+ it "should setup the matcher" do
73
+ OptionParser.stub(:new).and_yield(opts).and_return(opts)
74
+ opts.should_receive(:on).with("-c", "--concurrency COUNT", "The number of Workers [30]")
75
+
76
+ Howler::Runner.new
77
+ end
78
+
79
+ it "should set the argument" do
80
+ Howler::Runner.new.options[:concurrency].should == '50'
81
+ end
82
+ end
83
+
84
+ describe "for the path" do
85
+ before do
86
+ ARGV.replace(['-p', 'a/path/to/env.rb'])
87
+ end
88
+
89
+ it "should setup the matcher" do
90
+ OptionParser.stub(:new).and_yield(opts).and_return(opts)
91
+ opts.should_receive(:on).with("-p", "--path PATH", "The path to the file to load [./config/environment.rb]")
92
+
93
+ Howler::Runner.new
94
+ end
95
+
96
+ it "should set the argument" do
97
+ Howler::Runner.new.options[:path].should == 'a/path/to/env.rb'
98
+ end
99
+ end
100
+
101
+ describe "for the shutdown timeout" do
102
+ before do
103
+ ARGV.replace(['-s', '9'])
104
+ end
105
+
106
+ it "should setup the matcher" do
107
+ OptionParser.stub(:new).and_yield(opts).and_return(opts)
108
+ opts.should_receive(:on).with("-s", "--shutdown_timeout SECONDS", "The number of seconds to wait for workers to finish [5]")
109
+
110
+ Howler::Runner.new
111
+ end
112
+
113
+ it "should set the argument" do
114
+ Howler::Runner.new.options[:shutdown_timeout].should == '9'
115
+ end
116
+ end
117
+
118
+
119
+ it "should start the redis connection" do
120
+ redis = mock(Redis, :with => nil)
121
+ ARGV.replace(['-r', 'some/url:port'])
122
+
123
+ Howler.should_receive(:_redis).ordered.with('some/url:port')
124
+ Howler.should_receive(:redis).ordered.at_least(1).and_return(redis)
125
+
126
+ Howler::Runner.new
127
+ end
128
+
129
+ it "should store the config in Howler::Config" do
130
+ ARGV.replace(['-r', 'anything', '-c', '50'])
131
+
132
+ Howler::Config.stub(:[]=)
133
+
134
+ Howler::Config.should_receive(:[]=).with(:concurrency, '50')
135
+ Howler::Config.should_receive(:[]=).with(:redis_url, 'anything')
136
+
137
+ Howler::Runner.new
138
+ end
139
+ end
140
+
9
141
  describe "#run" do
10
142
  let!(:manager) { Howler::Manager.current }
11
143
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-10 00:00:00.000000000 Z
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis