promiscuous 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/promiscuous/version.rb +1 -1
- data/lib/promiscuous/worker.rb +27 -20
- metadata +2 -2
data/lib/promiscuous/version.rb
CHANGED
data/lib/promiscuous/worker.rb
CHANGED
@@ -1,33 +1,22 @@
|
|
1
1
|
module Promiscuous
|
2
2
|
module Worker
|
3
|
-
|
4
|
-
stop = false
|
5
|
-
lock = Mutex.new
|
3
|
+
mattr_accessor :stop
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
lock.synchronize do
|
11
|
-
stop = true
|
12
|
-
EM.stop
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
5
|
+
def self.replicate
|
6
|
+
self.stop = false
|
7
|
+
self.trap_signals unless ENV['TEST_ENV']
|
17
8
|
|
18
9
|
Promiscuous::AMQP.subscribe(subscribe_options) do |metadata, payload|
|
19
10
|
begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
metadata.ack
|
25
|
-
end
|
11
|
+
unless self.stop
|
12
|
+
Promiscuous.info "[receive] #{payload}"
|
13
|
+
self.mongoid_wrapper { Promiscuous::Subscriber.process(JSON.parse(payload)) }
|
14
|
+
metadata.ack
|
26
15
|
end
|
27
16
|
rescue Exception => e
|
28
17
|
e = Promiscuous::Subscriber::Error.new(e, payload)
|
29
18
|
|
30
|
-
stop = true
|
19
|
+
self.stop = true
|
31
20
|
Promiscuous::AMQP.disconnect
|
32
21
|
Promiscuous.error "[receive] FATAL #{e}"
|
33
22
|
Promiscuous::Config.error_handler.call(e) if Promiscuous::Config.error_handler
|
@@ -35,6 +24,24 @@ module Promiscuous
|
|
35
24
|
end
|
36
25
|
end
|
37
26
|
|
27
|
+
def self.mongoid_wrapper
|
28
|
+
if defined?(Mongoid)
|
29
|
+
Mongoid.unit_of_work { yield }
|
30
|
+
else
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.trap_signals
|
36
|
+
%w(SIGTERM SIGINT).each do |signal|
|
37
|
+
Signal.trap(signal) do
|
38
|
+
self.stop = true
|
39
|
+
EM.stop
|
40
|
+
Promiscuous.info "exiting gracefully"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
38
45
|
def self.subscribe_options
|
39
46
|
queue_name = "#{Promiscuous::Config.app}.promiscuous"
|
40
47
|
bindings = Promiscuous::Subscriber.subscribers.keys
|
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.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -135,8 +135,8 @@ files:
|
|
135
135
|
- lib/promiscuous/subscriber/mongoid/root.rb
|
136
136
|
- lib/promiscuous/subscriber/mongoid/upsert.rb
|
137
137
|
- lib/promiscuous/subscriber/polymorphic.rb
|
138
|
-
- lib/promiscuous/worker.rb
|
139
138
|
- lib/promiscuous/config.rb
|
139
|
+
- lib/promiscuous/worker.rb
|
140
140
|
- lib/promiscuous/version.rb
|
141
141
|
- README.md
|
142
142
|
homepage: http://github.com/crowdtap/promiscuous
|