howler 1.1.0 → 1.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/Gemfile.lock +1 -1
- data/lib/howler.rb +3 -3
- data/lib/howler/manager.rb +1 -1
- data/lib/howler/runner.rb +51 -4
- data/lib/howler/support/version.rb +1 -1
- data/spec/models/howler_spec.rb +1 -1
- data/spec/models/manager_spec.rb +28 -16
- data/spec/models/runner_spec.rb +132 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/howler.rb
CHANGED
@@ -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 =>
|
12
|
+
@connection ||= ConnectionPool.new(:timeout => 1, :size => 30) { _redis }
|
13
13
|
end
|
14
14
|
private
|
15
|
-
def self._redis
|
16
|
-
@redis ||= ::Redis.connect(:url =>
|
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
|
|
data/lib/howler/manager.rb
CHANGED
data/lib/howler/runner.rb
CHANGED
@@ -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
|
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
|
data/spec/models/howler_spec.rb
CHANGED
@@ -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 =>
|
49
|
+
ConnectionPool.should_receive(:new).with(:timeout => 1, :size => 30)
|
50
50
|
|
51
51
|
Howler.redis
|
52
52
|
end
|
data/spec/models/manager_spec.rb
CHANGED
@@ -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
|
-
|
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 "
|
219
|
+
describe "when there are messages" do
|
216
220
|
before do
|
217
|
-
|
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
|
-
|
221
|
-
|
226
|
+
describe "information" do
|
227
|
+
before do
|
228
|
+
Howler::Config[:log] = 'info'
|
229
|
+
end
|
222
230
|
|
223
|
-
|
224
|
-
|
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
|
-
|
228
|
-
|
229
|
-
Howler::Config[:log] = 'debug'
|
234
|
+
subject.run
|
235
|
+
end
|
230
236
|
end
|
231
237
|
|
232
|
-
|
233
|
-
|
234
|
-
|
238
|
+
describe "debug" do
|
239
|
+
before do
|
240
|
+
Howler::Config[:log] = 'debug'
|
241
|
+
end
|
235
242
|
|
236
|
-
|
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
|
data/spec/models/runner_spec.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2012-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|