superbolt 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -22
- data/lib/superbolt.rb +0 -1
- data/lib/superbolt/app.rb +6 -14
- data/lib/superbolt/config.rb +0 -4
- data/lib/superbolt/router.rb +1 -1
- data/lib/superbolt/runner/default.rb +5 -26
- data/lib/superbolt/version.rb +1 -1
- data/lib/tasks/superbolt.rake +1 -1
- data/spec/app_spec.rb +2 -29
- metadata +2 -4
- data/lib/superbolt/runner/active_record_deferrable.rb +0 -13
- data/spec/support/em_mocking.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 234d0975ce1b95e327ebefdd7f023a3ae9e36864
|
4
|
+
data.tar.gz: 86187f0b44f54b22365dfab163d5384036e1a670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d41cf6285e5b4853813eed6befe9c150cf83efbab3c882cd2c162a6edf7ab99ffa52611a75d38b898fc69ff76db3d27427bb6de8ff106ce9f09d45a2a053c3
|
7
|
+
data.tar.gz: 66f8359c9a4b88ab9997c2c1ea66d1281fd51f9a857777b102e63fc9f1b3d3a6e078e726441ffdb01bd628d8b21f873e58491c8064442e404b414cb8afd98b64
|
data/Rakefile
CHANGED
@@ -1,23 +1 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "superbolt/tasks"
|
3
|
-
|
4
|
-
|
5
|
-
# This one is for locally testing your crazy ideas
|
6
|
-
task :environment do
|
7
|
-
class MySleeperCell < Superbolt::MessageHandler
|
8
|
-
def perform
|
9
|
-
sleep(rand(10))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Superbolt.config = {
|
14
|
-
connection_params: {
|
15
|
-
host: '127.0.0.1',
|
16
|
-
heartbeat: 1,
|
17
|
-
}
|
18
|
-
}
|
19
|
-
Superbolt.app_name = 'food'
|
20
|
-
Superbolt::Router.routes = {
|
21
|
-
'do-it' => 'MySleeperCell'
|
22
|
-
}
|
23
|
-
end
|
data/lib/superbolt.rb
CHANGED
@@ -25,7 +25,6 @@ require "superbolt/runner/ack_one"
|
|
25
25
|
require "superbolt/runner/ack"
|
26
26
|
require "superbolt/runner/pop"
|
27
27
|
require "superbolt/runner/greedy"
|
28
|
-
require "superbolt/runner/active_record_deferrable"
|
29
28
|
|
30
29
|
require "superbolt/queue"
|
31
30
|
require "superbolt/incoming_message"
|
data/lib/superbolt/app.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Superbolt
|
2
2
|
class App
|
3
|
-
attr_reader :config, :env
|
3
|
+
attr_reader :config, :env, :runner_type
|
4
4
|
attr_accessor :logger
|
5
5
|
|
6
6
|
def initialize(name, options={})
|
7
7
|
@name = name
|
8
8
|
@env = options[:env] || Superbolt.env
|
9
9
|
@logger = options[:logger] || Logger.new($stdout)
|
10
|
+
@runner_type = options[:runner] || :default
|
10
11
|
@config = options[:config] || Superbolt.config
|
11
12
|
end
|
12
13
|
|
@@ -43,7 +44,7 @@ module Superbolt
|
|
43
44
|
EventMachine.run do
|
44
45
|
queue.channel.auto_recovery = true
|
45
46
|
|
46
|
-
# LShift came up with this solution, which helps reconnect when
|
47
|
+
# LShift came up with this solution, which helps reconnect when
|
47
48
|
# a process runs longer than the heartbeat (and therefore disconnects)
|
48
49
|
queue.channel.connection.on_tcp_connection_loss do |conn, settings|
|
49
50
|
puts 'Lost TCP connection, reconnecting'
|
@@ -59,7 +60,7 @@ module Superbolt
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def runner_class
|
62
|
-
runner_map[
|
63
|
+
runner_map[runner_type] || default_runner
|
63
64
|
end
|
64
65
|
|
65
66
|
def runner_map
|
@@ -67,17 +68,8 @@ module Superbolt
|
|
67
68
|
pop: Runner::Pop,
|
68
69
|
ack_one: Runner::AckOne,
|
69
70
|
ack: Runner::Ack,
|
70
|
-
greedy: Runner::Greedy
|
71
|
-
|
72
|
-
}.merge(self.class.additional_runners)
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.additional_runners
|
76
|
-
@additional_runners ||= {}
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.additional_runners=(ar)
|
80
|
-
@additional_runners = ar
|
71
|
+
greedy: Runner::Greedy
|
72
|
+
}
|
81
73
|
end
|
82
74
|
|
83
75
|
def default_runner
|
data/lib/superbolt/config.rb
CHANGED
data/lib/superbolt/router.rb
CHANGED
@@ -12,25 +12,12 @@ module Superbolt
|
|
12
12
|
|
13
13
|
def subscribe
|
14
14
|
queue.subscribe(ack: ack) do |metadata, payload|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
EM.defer do
|
20
|
-
after_fork
|
21
|
-
|
22
|
-
# this gets run on the thread pool
|
23
|
-
message = Superbolt::IncomingMessage.new(metadata, payload, channel)
|
24
|
-
processor = Superbolt::Processor.new(message, logger, &block)
|
25
|
-
unless processor.perform
|
26
|
-
on_error(message.parse, processor.exception)
|
27
|
-
end
|
28
|
-
|
29
|
-
EM.next_tick do
|
30
|
-
# this gets run back on the main loop
|
31
|
-
message.ack if ack
|
32
|
-
end
|
15
|
+
message = IncomingMessage.new(metadata, payload, channel)
|
16
|
+
processor = Processor.new(message, logger, &block)
|
17
|
+
unless processor.perform
|
18
|
+
on_error(message.parse, processor.exception)
|
33
19
|
end
|
20
|
+
message.ack if ack
|
34
21
|
end
|
35
22
|
end
|
36
23
|
|
@@ -39,14 +26,6 @@ module Superbolt
|
|
39
26
|
|
40
27
|
def prefetch
|
41
28
|
end
|
42
|
-
|
43
|
-
def before_fork
|
44
|
-
# Implement me in da subclass
|
45
|
-
end
|
46
|
-
|
47
|
-
def after_fork
|
48
|
-
# Implement me in da subclass
|
49
|
-
end
|
50
29
|
end
|
51
30
|
end
|
52
31
|
end
|
data/lib/superbolt/version.rb
CHANGED
data/lib/tasks/superbolt.rake
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# assumes an environment task that sets up your app environment
|
2
2
|
desc "worker that reads the queue and sends messages through the router as configured"
|
3
3
|
task :superbolt => :environment do
|
4
|
-
Superbolt::App.new(Superbolt.app_name
|
4
|
+
Superbolt::App.new(Superbolt.app_name).run do |message, logger|
|
5
5
|
Superbolt::Router.new(message, logger).perform
|
6
6
|
end
|
7
7
|
end
|
data/spec/app_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Superbolt::App do
|
|
5
5
|
Superbolt::App.new(name, {
|
6
6
|
env: env,
|
7
7
|
logger: logger,
|
8
|
-
|
8
|
+
runner: runner_type
|
9
9
|
})
|
10
10
|
}
|
11
11
|
|
@@ -23,7 +23,6 @@ describe Superbolt::App do
|
|
23
23
|
error_queue.clear
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
26
|
shared_examples 'app' do
|
28
27
|
it "shuts down with any message to the quit queue" do
|
29
28
|
queue.push({please: 'stop'})
|
@@ -64,6 +63,7 @@ describe Superbolt::App do
|
|
64
63
|
queue.size.should == 0
|
65
64
|
end
|
66
65
|
|
66
|
+
|
67
67
|
it "passes a logger to the block" do
|
68
68
|
mock_logger = double
|
69
69
|
app.logger = mock_logger
|
@@ -104,21 +104,6 @@ describe Superbolt::App do
|
|
104
104
|
it_should_behave_like "app"
|
105
105
|
end
|
106
106
|
|
107
|
-
context 'when runner acknowledges one and uses activerecord deferrable' do
|
108
|
-
let(:runner_type) { :ar_deferrable }
|
109
|
-
module ActiveRecord
|
110
|
-
class Base
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
before do
|
115
|
-
ActiveRecord::Base.stub(:connection).and_return(double('connection', disconnect!: true))
|
116
|
-
ActiveRecord::Base.stub(:establish_connection)
|
117
|
-
end
|
118
|
-
|
119
|
-
it_should_behave_like "app"
|
120
|
-
end
|
121
|
-
|
122
107
|
context 'when runner acknowledges without a prefetch limit' do
|
123
108
|
let(:runner_type) { :ack }
|
124
109
|
|
@@ -136,16 +121,4 @@ describe Superbolt::App do
|
|
136
121
|
|
137
122
|
it_should_behave_like "app"
|
138
123
|
end
|
139
|
-
|
140
|
-
context 'when there are additional runners in the apps config' do
|
141
|
-
let(:runner_type) { :monster_farts }
|
142
|
-
|
143
|
-
before do
|
144
|
-
Superbolt::App.additional_runners = {monster_farts: 'stinky'}
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'uses the injected runner' do
|
148
|
-
app.runner_class.should == 'stinky'
|
149
|
-
end
|
150
|
-
end
|
151
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superbolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- socialchorus
|
@@ -156,7 +156,6 @@ files:
|
|
156
156
|
- lib/superbolt/router.rb
|
157
157
|
- lib/superbolt/runner/ack.rb
|
158
158
|
- lib/superbolt/runner/ack_one.rb
|
159
|
-
- lib/superbolt/runner/active_record_deferrable.rb
|
160
159
|
- lib/superbolt/runner/base.rb
|
161
160
|
- lib/superbolt/runner/default.rb
|
162
161
|
- lib/superbolt/runner/greedy.rb
|
@@ -177,7 +176,6 @@ files:
|
|
177
176
|
- spec/spec_helper.rb
|
178
177
|
- spec/superbolt_spec.rb
|
179
178
|
- spec/support/commodore.jpg
|
180
|
-
- spec/support/em_mocking.rb
|
181
179
|
- spec/support/queue_helpers.rb
|
182
180
|
- superbolt.gemspec
|
183
181
|
homepage: ''
|
@@ -217,5 +215,5 @@ test_files:
|
|
217
215
|
- spec/spec_helper.rb
|
218
216
|
- spec/superbolt_spec.rb
|
219
217
|
- spec/support/commodore.jpg
|
220
|
-
- spec/support/em_mocking.rb
|
221
218
|
- spec/support/queue_helpers.rb
|
219
|
+
has_rdoc:
|