promiscuous 0.25 → 0.31.0
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/lib/promiscuous/amqp/bunny.rb +1 -1
- data/lib/promiscuous/amqp/null.rb +1 -0
- data/lib/promiscuous/amqp/ruby_amqp.rb +17 -14
- data/lib/promiscuous/amqp.rb +4 -2
- data/lib/promiscuous/cli.rb +9 -16
- data/lib/promiscuous/common.rb +1 -1
- data/lib/promiscuous/config.rb +4 -2
- data/lib/promiscuous/error/connection.rb +8 -1
- data/lib/promiscuous/error/publisher.rb +7 -1
- data/lib/promiscuous/publisher/active_record.rb +1 -0
- data/lib/promiscuous/publisher/amqp.rb +2 -1
- data/lib/promiscuous/publisher/base.rb +4 -0
- data/lib/promiscuous/publisher/lint.rb +1 -1
- data/lib/promiscuous/publisher/model/active_record.rb +25 -0
- data/lib/promiscuous/publisher/model/mongoid.rb +108 -0
- data/lib/promiscuous/publisher/model.rb +71 -19
- data/lib/promiscuous/publisher/mongoid/embedded.rb +8 -4
- data/lib/promiscuous/publisher/mongoid.rb +12 -9
- data/lib/promiscuous/publisher.rb +1 -1
- data/lib/promiscuous/redis.rb +52 -0
- data/lib/promiscuous/subscriber/mongoid.rb +1 -2
- data/lib/promiscuous/subscriber/worker/message.rb +46 -0
- data/lib/promiscuous/subscriber/worker/message_synchronizer.rb +168 -0
- data/lib/promiscuous/subscriber/worker/pump.rb +47 -0
- data/lib/promiscuous/subscriber/worker/runner.rb +7 -0
- data/lib/promiscuous/subscriber/worker.rb +39 -47
- data/lib/promiscuous/version.rb +1 -1
- data/lib/promiscuous/worker.rb +1 -5
- data/lib/promiscuous.rb +1 -1
- metadata +86 -20
- data/lib/promiscuous/common/worker.rb +0 -52
- data/lib/promiscuous/publisher/mongoid/defer.rb +0 -75
- data/lib/promiscuous/publisher/mongoid/defer_embedded.rb +0 -25
- data/lib/promiscuous/publisher/worker.rb +0 -101
- data/lib/promiscuous/subscriber/mongoid/versioning.rb +0 -40
@@ -0,0 +1,46 @@
|
|
1
|
+
class Promiscuous::Subscriber::Worker::Message
|
2
|
+
attr_accessor :worker, :metadata, :payload, :parsed_payload
|
3
|
+
|
4
|
+
def initialize(worker, metadata, payload)
|
5
|
+
self.worker = worker
|
6
|
+
self.metadata = metadata
|
7
|
+
self.payload = payload
|
8
|
+
end
|
9
|
+
|
10
|
+
def parsed_payload
|
11
|
+
@parsed_payload ||= JSON.parse(payload)
|
12
|
+
end
|
13
|
+
|
14
|
+
def queue_name
|
15
|
+
parsed_payload['__amqp__']
|
16
|
+
end
|
17
|
+
|
18
|
+
def has_version?
|
19
|
+
!!version
|
20
|
+
end
|
21
|
+
|
22
|
+
def version
|
23
|
+
@version ||= parsed_payload['version'].try(:symbolize_keys)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_dependencies
|
27
|
+
global_key = Promiscuous::Redis.sub_key('global')
|
28
|
+
global_version = Promiscuous::Redis.incr global_key
|
29
|
+
Promiscuous::Redis.publish(global_key, global_version)
|
30
|
+
end
|
31
|
+
|
32
|
+
def process
|
33
|
+
return if worker.stopped?
|
34
|
+
|
35
|
+
Promiscuous.debug "[receive] #{payload}"
|
36
|
+
|
37
|
+
worker.unit_of_work(queue_name) { Promiscuous::Subscriber.process(parsed_payload) }
|
38
|
+
|
39
|
+
update_dependencies
|
40
|
+
metadata.ack
|
41
|
+
rescue Exception => e
|
42
|
+
e = Promiscuous::Error::Subscriber.new(e, :payload => payload)
|
43
|
+
Promiscuous.warn "[receive] #{e} #{e.backtrace.join("\n")}"
|
44
|
+
Promiscuous::Config.error_notifier.try(:call, e)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
class Promiscuous::Subscriber::Worker::MessageSynchronizer
|
2
|
+
include Celluloid::IO
|
3
|
+
|
4
|
+
attr_accessor :worker, :redis
|
5
|
+
|
6
|
+
def initialize(worker)
|
7
|
+
self.worker = worker
|
8
|
+
@subscriptions = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def resume
|
12
|
+
self.redis = Promiscuous::Redis.new_celluloid_connection
|
13
|
+
main_loop!
|
14
|
+
end
|
15
|
+
|
16
|
+
def stop
|
17
|
+
terminate
|
18
|
+
end
|
19
|
+
|
20
|
+
def finalize
|
21
|
+
self.redis.client.connection.disconnect if self.redis
|
22
|
+
rescue
|
23
|
+
end
|
24
|
+
|
25
|
+
def main_loop
|
26
|
+
loop do
|
27
|
+
reply = redis.client.read
|
28
|
+
raise reply if reply.is_a?(Redis::CommandError)
|
29
|
+
type, subscription, arg = reply
|
30
|
+
|
31
|
+
case type
|
32
|
+
when 'subscribe'
|
33
|
+
find_subscription(subscription).finalize_subscription
|
34
|
+
when 'unsubscribe'
|
35
|
+
when 'message'
|
36
|
+
find_subscription(subscription).maybe_perform_callbacks(arg)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue Celluloid::Task::TerminatedError
|
40
|
+
rescue Exception => e
|
41
|
+
Promiscuous.warn "[redis] #{e} #{e.backtrace.join("\n")}"
|
42
|
+
|
43
|
+
e = Promiscuous::Error::Connection.new(:redis, 'Lost connection')
|
44
|
+
Promiscuous::Worker.stop
|
45
|
+
Promiscuous::Config.error_notifier.try(:call, e)
|
46
|
+
end
|
47
|
+
|
48
|
+
# process_when_ready() is called by the AMQP pump. This is what happens:
|
49
|
+
# 1. First, we subscribe to redis and wait for the confirmation.
|
50
|
+
# 2. Then we check if the version in redis is old enough to process the message.
|
51
|
+
# If not we bail out and rely on the subscription to kick the processing.
|
52
|
+
# Because we subscribed in advanced, we will not miss the notification, but
|
53
|
+
# extra care needs to be taken to avoid processing the message twice (see
|
54
|
+
# perform()).
|
55
|
+
def process_when_ready(msg)
|
56
|
+
return worker.runners.process!(msg) unless msg.has_version?
|
57
|
+
|
58
|
+
on_version Promiscuous::Redis.sub_key('global'), msg.version[:global] do
|
59
|
+
worker.runners.process!(msg)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def on_version(key, version, &callback)
|
64
|
+
return unless @subscriptions
|
65
|
+
cb = Subscription::Callback.new(version, callback)
|
66
|
+
get_subscription(key).subscribe.add_callback(version, cb)
|
67
|
+
cb.maybe_perform(Promiscuous::Redis.get(key))
|
68
|
+
end
|
69
|
+
|
70
|
+
# state_lock must be taken before calling find_subscription()
|
71
|
+
def find_subscription(key)
|
72
|
+
raise "Fatal error (redis sub)" unless @subscriptions[key]
|
73
|
+
@subscriptions[key]
|
74
|
+
end
|
75
|
+
|
76
|
+
# state_lock must be taken before calling find_subscription()
|
77
|
+
def get_subscription(key)
|
78
|
+
@subscriptions[key] ||= Subscription.new(self, key)
|
79
|
+
end
|
80
|
+
|
81
|
+
class Subscription
|
82
|
+
attr_accessor :parent, :key
|
83
|
+
|
84
|
+
def initialize(parent, key)
|
85
|
+
self.parent = parent
|
86
|
+
self.key = key
|
87
|
+
|
88
|
+
@subscription_requested = false
|
89
|
+
@subscribed_to_redis = false
|
90
|
+
@callbacks = {}
|
91
|
+
end
|
92
|
+
|
93
|
+
# subscribe() is called with the state_lock of the parent held
|
94
|
+
def subscribe
|
95
|
+
request_subscription
|
96
|
+
|
97
|
+
loop do
|
98
|
+
break if @subscribed_to_redis
|
99
|
+
parent.wait :subscription
|
100
|
+
end
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
def request_subscription
|
105
|
+
# We will not send two subscription requests, since we are holding
|
106
|
+
# the state_lock of the parent.
|
107
|
+
return if @subscription_requested
|
108
|
+
parent.redis.client.process([[:subscribe, key]])
|
109
|
+
@subscription_requested = true
|
110
|
+
end
|
111
|
+
|
112
|
+
def finalize_subscription
|
113
|
+
@subscribed_to_redis = true
|
114
|
+
parent.signal :subscription
|
115
|
+
end
|
116
|
+
|
117
|
+
def destroy
|
118
|
+
# TODO parent.redis_client_call(:unsubscribe, key)
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_callback(version, callback)
|
122
|
+
callback.subscription = self
|
123
|
+
@callbacks[callback.token] = callback
|
124
|
+
end
|
125
|
+
|
126
|
+
def remove_callback(token)
|
127
|
+
!!@callbacks.delete(token)
|
128
|
+
# TODO unsubscribe after a while?
|
129
|
+
end
|
130
|
+
|
131
|
+
def maybe_perform_callbacks(current_version)
|
132
|
+
@callbacks.values.each do |cb|
|
133
|
+
cb.maybe_perform(current_version)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class Callback
|
138
|
+
# Tokens are only used so that the callback can find and remove itself
|
139
|
+
# in the callback list.
|
140
|
+
@next_token = 0
|
141
|
+
def self.get_next_token
|
142
|
+
@next_token += 1
|
143
|
+
end
|
144
|
+
|
145
|
+
attr_accessor :subscription, :version, :callback, :token
|
146
|
+
|
147
|
+
def initialize(version, callback)
|
148
|
+
self.version = version
|
149
|
+
self.callback = callback
|
150
|
+
@token = self.class.get_next_token
|
151
|
+
end
|
152
|
+
|
153
|
+
def can_perform?(current_version)
|
154
|
+
current_version.to_i + 1 >= self.version
|
155
|
+
end
|
156
|
+
|
157
|
+
def perform
|
158
|
+
# removing the callback can happen only once, ensuring that the
|
159
|
+
# callback is called at most once.
|
160
|
+
callback.call if subscription.remove_callback(@token)
|
161
|
+
end
|
162
|
+
|
163
|
+
def maybe_perform(current_version)
|
164
|
+
perform if can_perform?(current_version)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Promiscuous::Subscriber::Worker::Pump
|
2
|
+
attr_accessor :worker
|
3
|
+
|
4
|
+
def initialize(worker)
|
5
|
+
self.worker = worker
|
6
|
+
end
|
7
|
+
|
8
|
+
def resume
|
9
|
+
if @queue
|
10
|
+
# XXX TODO we should not access to the channel like this.
|
11
|
+
# The abstraction is leaking.
|
12
|
+
# Actually, we actually want one channel per worker.
|
13
|
+
|
14
|
+
# The following tells rabbitmq to resend the unacked messages
|
15
|
+
Promiscuous::AMQP::RubyAMQP.channel.recover
|
16
|
+
else
|
17
|
+
Promiscuous::AMQP.open_queue(queue_bindings) do |queue|
|
18
|
+
@queue = queue
|
19
|
+
@queue.subscribe({:ack => true}, &method(:process_payload))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def stop
|
25
|
+
# we should tell amqp that we want to stop using the queue
|
26
|
+
end
|
27
|
+
|
28
|
+
def process_payload(metadata, payload)
|
29
|
+
return if worker.stopped?
|
30
|
+
|
31
|
+
msg = Promiscuous::Subscriber::Worker::Message.new(worker, metadata, payload)
|
32
|
+
worker.message_synchronizer.process_when_ready(msg)
|
33
|
+
end
|
34
|
+
|
35
|
+
def queue_bindings
|
36
|
+
queue_name = "#{Promiscuous::Config.app}.promiscuous"
|
37
|
+
exchange_name = Promiscuous::AMQP::EXCHANGE
|
38
|
+
|
39
|
+
if worker.options[:personality]
|
40
|
+
queue_name += ".#{worker.options[:personality]}"
|
41
|
+
exchange_name += ".#{worker.options[:personality]}"
|
42
|
+
end
|
43
|
+
|
44
|
+
bindings = Promiscuous::Subscriber::AMQP.subscribers.keys
|
45
|
+
{:exchange_name => exchange_name, :queue_name => queue_name, :bindings => bindings}
|
46
|
+
end
|
47
|
+
end
|
@@ -1,62 +1,54 @@
|
|
1
1
|
class Promiscuous::Subscriber::Worker
|
2
|
-
|
2
|
+
require 'celluloid'
|
3
|
+
require 'celluloid/io'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
# XXX TODO we should not access to the channel like this.
|
7
|
-
# The abstraction is leaking.
|
8
|
-
# Actually, we actually want one channel per worker.
|
5
|
+
extend Promiscuous::Autoload
|
6
|
+
autoload :Message, :Pump, :MessageSynchronizer, :Runner
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
else
|
13
|
-
Promiscuous::AMQP.open_queue(queue_bindings) do |queue|
|
14
|
-
@queue = queue
|
15
|
-
@queue.subscribe({:ack => true}, &method(:process_payload))
|
16
|
-
end
|
17
|
-
end
|
8
|
+
attr_accessor :options, :stopped, :pump, :message_synchronizer, :runners
|
9
|
+
alias_method :stopped?, :stopped
|
18
10
|
|
19
|
-
|
20
|
-
|
11
|
+
def initialize(options={})
|
12
|
+
Celluloid.exception_handler { |e| Promiscuous::Config.error_notifier.try(:call, e) }
|
21
13
|
|
22
|
-
|
23
|
-
return if self.stopped?
|
14
|
+
options[:personality] = 'new'
|
24
15
|
|
25
|
-
|
26
|
-
|
16
|
+
self.options = options
|
17
|
+
self.stopped = true
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
queue = parsed_payload['__amqp__']
|
19
|
+
self.pump = Pump.new(self)
|
20
|
+
end
|
31
21
|
|
32
|
-
|
22
|
+
def resume
|
23
|
+
return unless self.stopped
|
24
|
+
self.stopped = false
|
25
|
+
self.runners = Runner.pool
|
26
|
+
self.message_synchronizer = MessageSynchronizer.new(self)
|
27
|
+
self.message_synchronizer.resume
|
28
|
+
self.pump.resume
|
29
|
+
end
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
def stop
|
32
|
+
return if self.stopped
|
33
|
+
self.pump.stop
|
34
|
+
self.message_synchronizer.stop rescue Celluloid::Task::TerminatedError
|
35
|
+
self.message_synchronizer = nil
|
36
|
+
self.runners.terminate
|
37
|
+
self.runners = nil
|
38
|
+
self.stopped = true
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def unit_of_work(type, &block)
|
42
|
+
# type is used by the new relic agent, by monkey patching.
|
43
|
+
# middleware?
|
44
|
+
if defined?(Mongoid)
|
45
|
+
Mongoid.unit_of_work { yield }
|
42
46
|
else
|
43
|
-
|
44
|
-
Promiscuous.warn "[receive] (#{retry_msg}) #{e} #{e.backtrace.join("\n")}"
|
47
|
+
yield
|
45
48
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def queue_bindings
|
51
|
-
queue_name = "#{Promiscuous::Config.app}.promiscuous"
|
52
|
-
exchange_name = Promiscuous::AMQP::EXCHANGE
|
53
|
-
|
54
|
-
if options[:personality]
|
55
|
-
queue_name += ".#{options[:personality]}"
|
56
|
-
exchange_name += ".#{options[:personality]}"
|
49
|
+
ensure
|
50
|
+
if defined?(ActiveRecord)
|
51
|
+
ActiveRecord::Base.clear_active_connections!
|
57
52
|
end
|
58
|
-
|
59
|
-
bindings = Promiscuous::Subscriber::AMQP.subscribers.keys
|
60
|
-
{:exchange_name => exchange_name, :queue_name => queue_name, :bindings => bindings}
|
61
53
|
end
|
62
54
|
end
|
data/lib/promiscuous/version.rb
CHANGED
data/lib/promiscuous/worker.rb
CHANGED
@@ -3,11 +3,7 @@ module Promiscuous::Worker
|
|
3
3
|
self.workers = []
|
4
4
|
|
5
5
|
def self.replicate(options={})
|
6
|
-
options
|
7
|
-
actions = [options[:action]].flatten
|
8
|
-
|
9
|
-
self.workers << Promiscuous::Publisher::Worker.new(options).tap { |w| w.resume } if :publish.in? actions
|
10
|
-
self.workers << Promiscuous::Subscriber::Worker.new(options).tap { |w| w.resume } if :subscribe.in? actions
|
6
|
+
self.workers << Promiscuous::Subscriber::Worker.new(options).tap { |w| w.resume }
|
11
7
|
end
|
12
8
|
|
13
9
|
def self.kill
|
data/lib/promiscuous.rb
CHANGED
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:
|
4
|
+
version: 0.31.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -108,6 +108,70 @@ dependencies:
|
|
108
108
|
- - ! '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redis
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: crowdtap_redis_lock
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
type: :runtime
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: celluloid
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
type: :runtime
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: celluloid-io
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :runtime
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
111
175
|
description: Replicate your Mongoid/ActiveRecord models across your applications
|
112
176
|
email:
|
113
177
|
- nicolas@viennot.biz
|
@@ -117,36 +181,34 @@ executables:
|
|
117
181
|
extensions: []
|
118
182
|
extra_rdoc_files: []
|
119
183
|
files:
|
120
|
-
- lib/promiscuous/amqp/null.rb
|
121
184
|
- lib/promiscuous/amqp/bunny.rb
|
122
185
|
- lib/promiscuous/amqp/ruby_amqp.rb
|
186
|
+
- lib/promiscuous/amqp/null.rb
|
123
187
|
- lib/promiscuous/common/lint/base.rb
|
124
188
|
- lib/promiscuous/common/class_helpers.rb
|
125
189
|
- lib/promiscuous/common/options.rb
|
126
|
-
- lib/promiscuous/common/worker.rb
|
127
190
|
- lib/promiscuous/common/lint.rb
|
128
191
|
- lib/promiscuous/publisher/lint/amqp.rb
|
129
192
|
- lib/promiscuous/publisher/lint/attributes.rb
|
130
193
|
- lib/promiscuous/publisher/lint/base.rb
|
131
194
|
- lib/promiscuous/publisher/lint/polymorphic.rb
|
132
195
|
- lib/promiscuous/publisher/lint/class.rb
|
133
|
-
- lib/promiscuous/publisher/mongoid/embedded.rb
|
134
|
-
- lib/promiscuous/publisher/mongoid/defer_embedded.rb
|
135
196
|
- lib/promiscuous/publisher/mongoid/embedded_many.rb
|
136
|
-
- lib/promiscuous/publisher/mongoid/
|
197
|
+
- lib/promiscuous/publisher/mongoid/embedded.rb
|
198
|
+
- lib/promiscuous/publisher/model/active_record.rb
|
199
|
+
- lib/promiscuous/publisher/model/mongoid.rb
|
137
200
|
- lib/promiscuous/publisher/envelope.rb
|
138
201
|
- lib/promiscuous/publisher/polymorphic.rb
|
139
202
|
- lib/promiscuous/publisher/mock.rb
|
203
|
+
- lib/promiscuous/publisher/class.rb
|
204
|
+
- lib/promiscuous/publisher/ephemeral.rb
|
140
205
|
- lib/promiscuous/publisher/attributes.rb
|
141
|
-
- lib/promiscuous/publisher/model.rb
|
142
206
|
- lib/promiscuous/publisher/active_record.rb
|
143
207
|
- lib/promiscuous/publisher/base.rb
|
144
|
-
- lib/promiscuous/publisher/class.rb
|
145
|
-
- lib/promiscuous/publisher/ephemeral.rb
|
146
|
-
- lib/promiscuous/publisher/amqp.rb
|
147
|
-
- lib/promiscuous/publisher/worker.rb
|
148
|
-
- lib/promiscuous/publisher/mongoid.rb
|
149
208
|
- lib/promiscuous/publisher/lint.rb
|
209
|
+
- lib/promiscuous/publisher/mongoid.rb
|
210
|
+
- lib/promiscuous/publisher/amqp.rb
|
211
|
+
- lib/promiscuous/publisher/model.rb
|
150
212
|
- lib/promiscuous/subscriber/lint/amqp.rb
|
151
213
|
- lib/promiscuous/subscriber/lint/base.rb
|
152
214
|
- lib/promiscuous/subscriber/lint/class.rb
|
@@ -154,7 +216,10 @@ files:
|
|
154
216
|
- lib/promiscuous/subscriber/lint/attributes.rb
|
155
217
|
- lib/promiscuous/subscriber/mongoid/embedded_many.rb
|
156
218
|
- lib/promiscuous/subscriber/mongoid/embedded.rb
|
157
|
-
- lib/promiscuous/subscriber/
|
219
|
+
- lib/promiscuous/subscriber/worker/message.rb
|
220
|
+
- lib/promiscuous/subscriber/worker/runner.rb
|
221
|
+
- lib/promiscuous/subscriber/worker/pump.rb
|
222
|
+
- lib/promiscuous/subscriber/worker/message_synchronizer.rb
|
158
223
|
- lib/promiscuous/subscriber/active_record.rb
|
159
224
|
- lib/promiscuous/subscriber/envelope.rb
|
160
225
|
- lib/promiscuous/subscriber/upsert.rb
|
@@ -165,25 +230,26 @@ files:
|
|
165
230
|
- lib/promiscuous/subscriber/model.rb
|
166
231
|
- lib/promiscuous/subscriber/base.rb
|
167
232
|
- lib/promiscuous/subscriber/class.rb
|
168
|
-
- lib/promiscuous/subscriber/mongoid.rb
|
169
233
|
- lib/promiscuous/subscriber/lint.rb
|
234
|
+
- lib/promiscuous/subscriber/mongoid.rb
|
170
235
|
- lib/promiscuous/subscriber/worker.rb
|
236
|
+
- lib/promiscuous/error/subscriber.rb
|
171
237
|
- lib/promiscuous/error/connection.rb
|
172
238
|
- lib/promiscuous/error/publisher.rb
|
173
|
-
- lib/promiscuous/error/subscriber.rb
|
174
239
|
- lib/promiscuous/observer.rb
|
175
240
|
- lib/promiscuous/ephemeral.rb
|
176
|
-
- lib/promiscuous/worker.rb
|
177
241
|
- lib/promiscuous/autoload.rb
|
178
242
|
- lib/promiscuous/subscriber.rb
|
179
|
-
- lib/promiscuous/publisher.rb
|
180
243
|
- lib/promiscuous/error.rb
|
181
|
-
- lib/promiscuous/common.rb
|
182
|
-
- lib/promiscuous/amqp.rb
|
183
244
|
- lib/promiscuous/loader.rb
|
184
245
|
- lib/promiscuous/railtie.rb
|
185
246
|
- lib/promiscuous/cli.rb
|
247
|
+
- lib/promiscuous/common.rb
|
248
|
+
- lib/promiscuous/publisher.rb
|
249
|
+
- lib/promiscuous/worker.rb
|
250
|
+
- lib/promiscuous/amqp.rb
|
186
251
|
- lib/promiscuous/config.rb
|
252
|
+
- lib/promiscuous/redis.rb
|
187
253
|
- lib/promiscuous/version.rb
|
188
254
|
- lib/promiscuous.rb
|
189
255
|
- bin/promiscuous
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Promiscuous::Common::Worker
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
def initialize(options={})
|
5
|
-
self.options = options
|
6
|
-
self.stopped = true
|
7
|
-
made_progress
|
8
|
-
end
|
9
|
-
|
10
|
-
def stop
|
11
|
-
self.stopped = true
|
12
|
-
end
|
13
|
-
|
14
|
-
def resume
|
15
|
-
self.stopped = false
|
16
|
-
end
|
17
|
-
|
18
|
-
def unit_of_work(type)
|
19
|
-
# type is used by the new relic agent, by monkey patching.
|
20
|
-
# middleware?
|
21
|
-
if defined?(Mongoid)
|
22
|
-
Mongoid.unit_of_work { yield }
|
23
|
-
else
|
24
|
-
yield
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def bareback?
|
29
|
-
!!options[:bareback]
|
30
|
-
end
|
31
|
-
|
32
|
-
def stop_for_a_while(reason)
|
33
|
-
stop
|
34
|
-
self.retry_timeout = self.retry_timeout * 2
|
35
|
-
|
36
|
-
if reason.inner.is_a? Promiscuous::Error::Connection
|
37
|
-
"will retry when the amqp connection comes back"
|
38
|
-
else
|
39
|
-
EM::Timer.new(self.retry_timeout) { resume }
|
40
|
-
"retrying in #{self.retry_timeout}s"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def made_progress
|
45
|
-
self.retry_timeout = 1
|
46
|
-
end
|
47
|
-
|
48
|
-
included do
|
49
|
-
attr_accessor :stopped, :options, :retry_timeout
|
50
|
-
alias_method :stopped?, :stopped
|
51
|
-
end
|
52
|
-
end
|