promiscuous 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/promiscuous.rb CHANGED
@@ -26,6 +26,16 @@ module Promiscuous
26
26
  desc.each { |klass| klass.setup_class_binding }
27
27
  end
28
28
 
29
+ def connect
30
+ AMQP.connect
31
+ Redis.connect
32
+ end
33
+
34
+ def disconnect
35
+ AMQP.disconnect
36
+ Redis.disconnect
37
+ end
38
+
29
39
  def healthy?
30
40
  AMQP.ensure_connected
31
41
  Redis.ensure_connected
@@ -21,6 +21,7 @@ module Promiscuous::AMQP
21
21
 
22
22
  def publish(options={})
23
23
  ensure_connected
24
+ Promiscuous.debug "[publish] (#{options[:exchange_name]}) #{options[:key]} -> #{options[:payload]}"
24
25
  backend.publish(options)
25
26
  end
26
27
 
@@ -16,7 +16,6 @@ module Promiscuous::AMQP:: Bunny
16
16
  end
17
17
 
18
18
  def self.publish(options={})
19
- Promiscuous.debug "[publish] (#{options[:exchange_name]}) #{options[:key]} -> #{options[:payload]}"
20
19
  exchange(options[:exchange_name]).
21
20
  publish(options[:payload], :key => options[:key], :persistent => true)
22
21
  end
@@ -79,9 +79,6 @@ module Promiscuous::AMQP::RubyAMQP
79
79
  end
80
80
 
81
81
  def self.publish(options={})
82
- info_msg = "(#{options[:exchange_name]}) #{options[:key]} -> #{options[:payload]}"
83
- Promiscuous.debug "[publish] #{info_msg}"
84
-
85
82
  EM.next_tick do
86
83
  exchange(options[:exchange_name]).
87
84
  publish(options[:payload], :routing_key => options[:key], :persistent => true)
@@ -12,9 +12,9 @@ class Promiscuous::CLI
12
12
  end
13
13
 
14
14
  def force_backend(backend)
15
- Promiscuous::AMQP.disconnect
15
+ Promiscuous.disconnect
16
16
  Promiscuous::Config.backend = backend
17
- Promiscuous::AMQP.connect
17
+ Promiscuous.connect
18
18
  end
19
19
 
20
20
  def trap_signals
@@ -16,7 +16,6 @@ module Promiscuous::Config
16
16
  self.queue_options ||= {:durable => true, :arguments => {'x-ha-policy' => 'all'}}
17
17
  self.heartbeat ||= 60
18
18
 
19
- Promiscuous::AMQP.connect
20
- Promiscuous::Redis.connect
19
+ Promiscuous.connect
21
20
  end
22
21
  end
@@ -4,9 +4,15 @@ module Promiscuous::Redis
4
4
  mattr_accessor :master
5
5
 
6
6
  def self.connect
7
+ disconnect if self.master
7
8
  self.master = new_connection
8
9
  end
9
10
 
11
+ def self.disconnect
12
+ self.master.client.disconnect
13
+ self.master = nil
14
+ end
15
+
10
16
  def self.new_connection
11
17
  return Null.new if Promiscuous::Config.backend == :null
12
18
 
@@ -1,7 +1,7 @@
1
1
  module Promiscuous::Subscriber
2
2
  extend Promiscuous::Autoload
3
3
  autoload :ActiveRecord, :AMQP, :Attributes, :Base, :Class, :Envelope, :Error,
4
- :Lint, :Model, :Mongoid, :Polymorphic, :Upsert, :Observer, :Worker
4
+ :Lint, :Model, :Mongoid, :Polymorphic, :Upsert, :Observer, :Worker, :Dummy
5
5
 
6
6
  def self.lint(*args)
7
7
  Lint.lint(*args)
@@ -7,10 +7,8 @@ module Promiscuous::Subscriber::AMQP
7
7
 
8
8
  def self.subscriber_from(payload)
9
9
  if key = payload.is_a?(Hash) ? payload['__amqp__'] : nil
10
- unless self.subscribers.has_key?(key)
11
- raise "Unknown binding: '#{key}'"
12
- end
13
- self.subscribers[key]
10
+ sub = self.subscribers[key]
11
+ sub ||= Promiscuous::Subscriber::Dummy
14
12
  end
15
13
  end
16
14
 
@@ -0,0 +1,19 @@
1
+ class Promiscuous::Subscriber::Dummy < Promiscuous::Subscriber::Base
2
+ include Promiscuous::Subscriber::Class
3
+ include Promiscuous::Subscriber::Attributes
4
+ include Promiscuous::Subscriber::AMQP
5
+ include Promiscuous::Subscriber::Envelope
6
+ include Promiscuous::Subscriber::Model
7
+
8
+ class DummyInstance
9
+ attr_accessor :id
10
+ end
11
+
12
+ def klass
13
+ DummyInstance
14
+ end
15
+
16
+ def operation
17
+ :dummy
18
+ end
19
+ end
@@ -93,6 +93,7 @@ module Promiscuous::Subscriber::Model
93
93
  when :create then instance.save!
94
94
  when :update then instance.save!
95
95
  when :destroy then instance.destroy
96
+ when :dummy then nil
96
97
  end
97
98
  end
98
99
  end
@@ -29,10 +29,14 @@ class Promiscuous::Subscriber::Worker
29
29
  def stop
30
30
  return if self.stopped
31
31
  self.pump.stop
32
- self.message_synchronizer.stop rescue Celluloid::Task::TerminatedError
33
- self.message_synchronizer = nil
34
- self.runners.terminate
35
- self.runners = nil
32
+ if self.message_synchronizer
33
+ self.message_synchronizer.stop rescue Celluloid::Task::TerminatedError
34
+ self.message_synchronizer = nil
35
+ end
36
+ if self.runners
37
+ self.runners.terminate
38
+ self.runners = nil
39
+ end
36
40
  self.stopped = true
37
41
  # TODO wait for the runners to finish
38
42
  end
@@ -37,7 +37,8 @@ class Promiscuous::Subscriber::Worker::Pump
37
37
  exchange_name += ".#{worker.options[:personality]}"
38
38
  end
39
39
 
40
- bindings = Promiscuous::Subscriber::AMQP.subscribers.keys
40
+ # We need to subscribe to everything to keep up with the version tracking
41
+ bindings = ['*']
41
42
  {:exchange_name => exchange_name, :queue_name => queue_name, :bindings => bindings}
42
43
  end
43
44
  end
@@ -1,3 +1,3 @@
1
1
  module Promiscuous
2
- VERSION = '0.32.0'
2
+ VERSION = '0.33.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promiscuous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.33.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -182,8 +182,8 @@ extensions: []
182
182
  extra_rdoc_files: []
183
183
  files:
184
184
  - lib/promiscuous/amqp/null.rb
185
- - lib/promiscuous/amqp/bunny.rb
186
185
  - lib/promiscuous/amqp/ruby_amqp.rb
186
+ - lib/promiscuous/amqp/bunny.rb
187
187
  - lib/promiscuous/common/lint/base.rb
188
188
  - lib/promiscuous/common/class_helpers.rb
189
189
  - lib/promiscuous/common/options.rb
@@ -216,39 +216,40 @@ files:
216
216
  - lib/promiscuous/subscriber/lint/attributes.rb
217
217
  - lib/promiscuous/subscriber/mongoid/embedded_many.rb
218
218
  - lib/promiscuous/subscriber/mongoid/embedded.rb
219
- - lib/promiscuous/subscriber/worker/pump.rb
220
219
  - lib/promiscuous/subscriber/worker/runner.rb
221
220
  - lib/promiscuous/subscriber/worker/message_synchronizer.rb
221
+ - lib/promiscuous/subscriber/worker/pump.rb
222
222
  - lib/promiscuous/subscriber/worker/message.rb
223
223
  - lib/promiscuous/subscriber/active_record.rb
224
224
  - lib/promiscuous/subscriber/envelope.rb
225
225
  - lib/promiscuous/subscriber/upsert.rb
226
226
  - lib/promiscuous/subscriber/polymorphic.rb
227
- - lib/promiscuous/subscriber/amqp.rb
228
227
  - lib/promiscuous/subscriber/attributes.rb
229
228
  - lib/promiscuous/subscriber/base.rb
230
229
  - lib/promiscuous/subscriber/class.rb
231
230
  - lib/promiscuous/subscriber/lint.rb
232
231
  - lib/promiscuous/subscriber/mongoid.rb
233
232
  - lib/promiscuous/subscriber/observer.rb
234
- - lib/promiscuous/subscriber/worker.rb
235
233
  - lib/promiscuous/subscriber/model.rb
234
+ - lib/promiscuous/subscriber/amqp.rb
235
+ - lib/promiscuous/subscriber/dummy.rb
236
+ - lib/promiscuous/subscriber/worker.rb
236
237
  - lib/promiscuous/error/subscriber.rb
237
238
  - lib/promiscuous/error/publisher.rb
238
239
  - lib/promiscuous/error/connection.rb
239
240
  - lib/promiscuous/observer.rb
240
241
  - lib/promiscuous/ephemeral.rb
241
242
  - lib/promiscuous/autoload.rb
242
- - lib/promiscuous/subscriber.rb
243
243
  - lib/promiscuous/error.rb
244
244
  - lib/promiscuous/loader.rb
245
245
  - lib/promiscuous/railtie.rb
246
246
  - lib/promiscuous/common.rb
247
247
  - lib/promiscuous/publisher.rb
248
248
  - lib/promiscuous/worker.rb
249
- - lib/promiscuous/config.rb
250
249
  - lib/promiscuous/amqp.rb
250
+ - lib/promiscuous/subscriber.rb
251
251
  - lib/promiscuous/redis.rb
252
+ - lib/promiscuous/config.rb
252
253
  - lib/promiscuous/cli.rb
253
254
  - lib/promiscuous/version.rb
254
255
  - lib/promiscuous.rb