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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 993a942222be7e90d9ceb4abf46ba30cfb3f7635
4
- data.tar.gz: 076f2935f293964db9a7942f049f44ccf165f0db
3
+ metadata.gz: 234d0975ce1b95e327ebefdd7f023a3ae9e36864
4
+ data.tar.gz: 86187f0b44f54b22365dfab163d5384036e1a670
5
5
  SHA512:
6
- metadata.gz: 32bca69f1e4c42a0327f0c72142180351d09cdcb00e1f2276850d454f7f038ef47fafe081c48f884a3469cf655421e0486f4c7ca913f5de92b318d09fc9990a3
7
- data.tar.gz: 48217dbf508298a7a0f16a4e3ba094f916e13d013a601bebfbd11b2b25422d9a34c47c8ed8fcea4a64f29bea38a9f94ac21057d5949926a9dd9076dc4252dd7e
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
@@ -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"
@@ -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[config.runner_type] || default_runner
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
- ar_deferrable: Runner::ActiveRecordDeferrable
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
@@ -23,10 +23,6 @@ module Superbolt
23
23
  options[:connection_key] || 'RABBITMQ_URL'
24
24
  end
25
25
 
26
- def runner_type
27
- options[:runner_type_key] ? ENV[options[:runner_type_key]].to_sym : :default
28
- end
29
-
30
26
  def env_params
31
27
  ENV[env_connection_key]
32
28
  end
@@ -21,7 +21,7 @@ module Superbolt
21
21
 
22
22
  def perform
23
23
  if handler_class
24
- handler_class.new(arguments, logger).perform
24
+ handler_class.new(arguments, logger).perform
25
25
  else
26
26
  logger.warn "No Superbolt route for event: '#{event}'"
27
27
  end
@@ -12,25 +12,12 @@ module Superbolt
12
12
 
13
13
  def subscribe
14
14
  queue.subscribe(ack: ack) do |metadata, payload|
15
- #Thanks again to LShift for this solution to long-running processes
16
- #Defer keeps heartbeat running while the process finishes
17
-
18
- before_fork
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
@@ -1,3 +1,3 @@
1
1
  module Superbolt
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -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, {}).run do |message, logger|
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
@@ -5,7 +5,7 @@ describe Superbolt::App do
5
5
  Superbolt::App.new(name, {
6
6
  env: env,
7
7
  logger: logger,
8
- config: double('config', runner_type: runner_type, connection_params: true)
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
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:
@@ -1,13 +0,0 @@
1
- module Superbolt
2
- module Runner
3
- class ActiveRecordDeferrable < AckOne
4
- def before_fork
5
- ActiveRecord::Base.connection.disconnect!
6
- end
7
-
8
- def after_fork
9
- ActiveRecord::Base.establish_connection
10
- end
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- module EM
2
- def self.defer(&block)
3
- block.call
4
- end
5
-
6
- def self.next_tick(&block)
7
- block.call
8
- end
9
- end