multiple_man 0.5.4 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multiple_man/connection.rb +0 -6
- data/lib/multiple_man/listener.rb +9 -5
- data/lib/multiple_man/mixins/publisher.rb +4 -2
- data/lib/multiple_man/model_populator.rb +2 -1
- data/lib/multiple_man/subscribers/model_subscriber.rb +3 -2
- data/lib/multiple_man/tasks/worker.rake +7 -5
- data/lib/multiple_man/version.rb +1 -1
- data/spec/model_populator_spec.rb +6 -2
- data/spec/subscribers/model_subscriber_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e44faf7da3f696f3be2d903a0f98edc74f9e78
|
4
|
+
data.tar.gz: 2e38d9f0254ec62714bda7e0d1054048c2e18d34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcfc3ba3affb5f65c7ba5e570ca6cc097c658e11fdb566d5feb1c2adde844acdd23e366336097c0ef0ae81576a60112432a55b19e42827aef76fc5a15c0ec9b0
|
7
|
+
data.tar.gz: 6c97e8e20ac7eed431e52cdf582504f6bf13a555087b9cecaed73862ddc609524712ed61a6a48d5b3a73be8179a08475dad6f8a9d8eb452c6a0add2e8e0cc407
|
@@ -42,10 +42,4 @@ module MultipleMan
|
|
42
42
|
attr_accessor :channel
|
43
43
|
|
44
44
|
end
|
45
|
-
|
46
|
-
class ListenerConnection < Connection
|
47
|
-
def self.channel_pool
|
48
|
-
@channel_pool ||= ConnectionPool.new(size: 25, timeout: 5) { connection.create_channel(nil, MultipleMan.configuration.worker_concurrency) }
|
49
|
-
end
|
50
|
-
end
|
51
45
|
end
|
@@ -38,17 +38,21 @@ module MultipleMan
|
|
38
38
|
begin
|
39
39
|
subscription.send(operation(delivery_info), JSON.parse(payload).with_indifferent_access)
|
40
40
|
rescue Exception => ex
|
41
|
-
|
42
|
-
MultipleMan.error(ex)
|
43
|
-
|
44
|
-
# Requeue the message
|
45
|
-
queue.channel.nack(delivery_info.delivery_tag, false, true)
|
41
|
+
handle_error(ex, delivery_info)
|
46
42
|
else
|
47
43
|
MultipleMan.logger.debug " Successfully processed!"
|
48
44
|
queue.channel.acknowledge(delivery_info.delivery_tag, false)
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
48
|
+
def handle_error(ex, delivery_info)
|
49
|
+
MultipleMan.logger.error " Error - #{ex.message}\n\n#{ex.backtrace}"
|
50
|
+
MultipleMan.error(ex)
|
51
|
+
|
52
|
+
# Requeue the message
|
53
|
+
queue.channel.nack(delivery_info.delivery_tag, false, true)
|
54
|
+
end
|
55
|
+
|
52
56
|
def operation(delivery_info)
|
53
57
|
delivery_info.routing_key.split(".").last
|
54
58
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
1
3
|
module MultipleMan
|
2
4
|
module Publisher
|
3
5
|
def Publisher.included(base)
|
@@ -5,6 +7,8 @@ module MultipleMan
|
|
5
7
|
base.after_commit(on: :create) { |r| r.multiple_man_publish(:create) }
|
6
8
|
base.after_commit(on: :update) { |r| r.multiple_man_publish(:update) }
|
7
9
|
base.after_commit(on: :destroy) { |r| r.multiple_man_publish(:destroy) }
|
10
|
+
|
11
|
+
base.class_attribute :multiple_man_publisher
|
8
12
|
end
|
9
13
|
|
10
14
|
def multiple_man_publish(operation=:create)
|
@@ -17,8 +21,6 @@ module MultipleMan
|
|
17
21
|
multiple_man_publisher.publish(self, operation)
|
18
22
|
end
|
19
23
|
|
20
|
-
attr_accessor :multiple_man_publisher
|
21
|
-
|
22
24
|
def publish(options = {})
|
23
25
|
self.multiple_man_publisher = ModelPublisher.new(options)
|
24
26
|
end
|
@@ -9,8 +9,9 @@ module MultipleMan::Subscribers
|
|
9
9
|
attr_accessor :options
|
10
10
|
|
11
11
|
def create(payload)
|
12
|
-
|
13
|
-
|
12
|
+
id = payload[:id]
|
13
|
+
model = find_model(id)
|
14
|
+
MultipleMan::ModelPopulator.new(model, options[:fields]).populate(id: find_conditions(id), data: payload[:data])
|
14
15
|
model.save!
|
15
16
|
end
|
16
17
|
|
@@ -12,12 +12,14 @@ namespace :multiple_man do
|
|
12
12
|
def run_listener(listener)
|
13
13
|
Rails.application.eager_load!
|
14
14
|
|
15
|
-
MultipleMan::
|
16
|
-
|
15
|
+
channel = MultipleMan::Connection.connection.create_channel(nil, MultipleMan.configuration.worker_concurrency)
|
16
|
+
channel.prefetch(100)
|
17
|
+
connection = MultipleMan::Connection.new(channel)
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
listener.start(connection)
|
20
|
+
|
21
|
+
while(true)
|
22
|
+
sleep 10
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/multiple_man/version.rb
CHANGED
@@ -2,13 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MultipleMan::ModelPopulator do
|
4
4
|
class MockModel
|
5
|
-
attr_accessor :a, :b
|
5
|
+
attr_accessor :a, :b, :multiple_man_identifier
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "populate" do
|
9
9
|
let(:model) { MockModel.new }
|
10
10
|
let(:data) { { a: 1, b: 2 } }
|
11
|
-
|
11
|
+
let(:id) { { multiple_man_identifier: 'app_1' }}
|
12
|
+
let(:fields) { nil }
|
13
|
+
subject { described_class.new(model, fields).populate(id: id, data: data) }
|
14
|
+
|
15
|
+
its(:multiple_man_identifier) { should == 'app_1' }
|
12
16
|
|
13
17
|
context "with fields defined" do
|
14
18
|
let(:fields) { [:a] }
|
@@ -11,10 +11,10 @@ describe MultipleMan::Subscribers::ModelSubscriber do
|
|
11
11
|
MockClass.stub(:where).and_return([mock_object])
|
12
12
|
mock_populator = double(MultipleMan::ModelPopulator)
|
13
13
|
MultipleMan::ModelPopulator.should_receive(:new).and_return(mock_populator)
|
14
|
-
mock_populator.should_receive(:populate).with({a: 1, b: 2})
|
14
|
+
mock_populator.should_receive(:populate).with(id: {id:5}, data: {a: 1, b: 2})
|
15
15
|
mock_object.should_receive(:save!)
|
16
16
|
|
17
|
-
described_class.new(MockClass, {}).create({id: 5, data:{a: 1, b: 2}})
|
17
|
+
described_class.new(MockClass, {}).create({id: {id: 5}, data:{a: 1, b: 2}})
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiple_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|