multiple_man 0.5.4 → 0.5.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7f3ae4586ac85cd7d1137f02cb17c1aa699d544
4
- data.tar.gz: 39fa794bba96809a3018738c7b899df2b20b17a1
3
+ metadata.gz: 74e44faf7da3f696f3be2d903a0f98edc74f9e78
4
+ data.tar.gz: 2e38d9f0254ec62714bda7e0d1054048c2e18d34
5
5
  SHA512:
6
- metadata.gz: 8346e9fa5130b1ceb3476e1e43394f39dc11e4ae37058caae87fe35f111aa3655d59e459678562ad043e606bdfc0a9280cd2c5a7e68146625c28f6eebc754523
7
- data.tar.gz: a638ac410b4ad19f70d0a559458c7d065c81c3271351101eefbd50f08453f44c53945ab6fb80003b0780cc024b62fd71750b09940f5d27833e21d0bbd63757e1
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
- MultipleMan.logger.error " Error - #{ex.message}\n\n#{ex.backtrace}"
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
@@ -6,7 +6,8 @@ module MultipleMan
6
6
  self.fields = fields
7
7
  end
8
8
 
9
- def populate(data)
9
+ def populate(payload)
10
+ data = payload[:id].merge(payload[:data])
10
11
  fields_for(data).each do |field|
11
12
  populate_field(field, data[field])
12
13
  end
@@ -9,8 +9,9 @@ module MultipleMan::Subscribers
9
9
  attr_accessor :options
10
10
 
11
11
  def create(payload)
12
- model = find_model(payload[:id])
13
- MultipleMan::ModelPopulator.new(model, options[:fields]).populate(payload[:data])
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::ListenerConnection.connect do |connection|
16
- listener.start(connection)
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
- while(true)
19
- sleep 10
20
- end
19
+ listener.start(connection)
20
+
21
+ while(true)
22
+ sleep 10
21
23
  end
22
24
  end
23
25
  end
@@ -1,3 +1,3 @@
1
1
  module MultipleMan
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.6"
3
3
  end
@@ -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
- subject { described_class.new(model, fields).populate(data) }
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
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-07 00:00:00.000000000 Z
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler