promiscuous 0.100.2 → 0.100.3

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: f03baccd94bfc3544565c1d22949b5c9a27837ff
4
- data.tar.gz: 37b69e7efed0d7b8e0d89e6dfd7f78610ec2bef7
3
+ metadata.gz: 661ee6c4ebf5e97d57ba23bc894dec27875b51da
4
+ data.tar.gz: 0c803f496368153a921f2e1a377f8164c65574b6
5
5
  SHA512:
6
- metadata.gz: 4c41185a3ba9ec6ef9e9df5bfbe688b050085ee3aa723a89a5c6f549797d2ff2d7cf2142f23ac631ef483f4d7e80a4013bf8e6534b22d04e44f14360eb6decb5
7
- data.tar.gz: 7d1aba8027e95a1e6760e2cf9020b349d2d5fb99c42e54064f82abc689803d79d446b46421cfc95c44eb43a1b239ad2c6a54f3458473043518feee0e0ff5ebcf
6
+ metadata.gz: 62dce82bf3dae1f68f6fdeb895059162c3e66e82587096a6b2d6ee6ebd6a1bbbae4cdcb95cb19e417ac4b712a33785e39521206f1206f33f3559a30c55e60b79
7
+ data.tar.gz: 90926a0597ef13645fdb17aeca623f28fe57bf6101208d73f529c82812162ce133a8893411a93c3392c24832b343d6423a5db82640379f942757b7aea6efca57
@@ -20,7 +20,7 @@ class Promiscuous::Subscriber::Message
20
20
  end
21
21
 
22
22
  def generation
23
- parsed_payload['generation']
23
+ parsed_payload['generation'] || 0
24
24
  end
25
25
 
26
26
  def dependencies
@@ -3,9 +3,9 @@ module Promiscuous::Subscriber::Model::Base
3
3
 
4
4
  def __promiscuous_eventual_consistency_update(operation)
5
5
  return true unless self.respond_to?(:attributes)
6
- return true unless operation.version
6
+ return true unless operation.dependency.try(&:version)
7
7
 
8
- version = operation.version
8
+ version = operation.dependency.version
9
9
  generation = operation.message.generation
10
10
  version = (generation << 50) | version
11
11
 
@@ -1,5 +1,5 @@
1
1
  class Promiscuous::Subscriber::Operation
2
- attr_accessor :model, :id, :operation, :attributes, :version
2
+ attr_accessor :model, :id, :operation, :attributes, :dependency
3
3
  delegate :message, :to => :unit_of_work
4
4
 
5
5
  def initialize(payload)
@@ -7,7 +7,7 @@ class Promiscuous::Subscriber::Operation
7
7
  self.id = payload['id']
8
8
  self.operation = payload['operation'].try(:to_sym)
9
9
  self.attributes = payload['attributes']
10
- self.version = payload['version']
10
+ self.dependency = payload['dependency']
11
11
  self.model = self.get_subscribed_model(payload) if payload['types']
12
12
  end
13
13
  end
@@ -29,6 +29,7 @@ class Promiscuous::Subscriber::Operation
29
29
 
30
30
  def create(options={})
31
31
  model.__promiscuous_fetch_new(id).tap do |instance|
32
+ instance.__promiscuous_eventual_consistency_update(self)
32
33
  instance.__promiscuous_update(self)
33
34
  instance.save!
34
35
  end
@@ -13,7 +13,7 @@ class Promiscuous::Subscriber::UnitOfWork
13
13
  def operations
14
14
  message.parsed_payload['operations'].
15
15
  each_with_index.
16
- map { |op, i| Promiscuous::Subscriber::Operation.new(op.merge('version' => message.dependencies[i].try(&:version))) }
16
+ map { |op, i| Promiscuous::Subscriber::Operation.new(op.merge('dependency' => message.dependencies[i])) }
17
17
  end
18
18
 
19
19
  def self.process(*args)
@@ -51,23 +51,15 @@ class Promiscuous::Subscriber::UnitOfWork
51
51
  end
52
52
  end
53
53
 
54
- def instance_dep
55
- @instance_dep ||= dependencies.first
56
- end
57
-
58
- def master_node
59
- @master_node ||= instance_dep.redis_node
60
- end
61
-
62
54
  LOCK_OPTIONS = { :timeout => 1.5.minute, # after 1.5 minute, we give up
63
55
  :sleep => 0.1, # polling every 100ms.
64
56
  :expire => 1.minute } # after one minute, we are considered dead
65
57
 
66
- def with_instance_locked(&block)
67
- return yield unless message.has_dependencies?
58
+ def with_instance_locked_for(operation, &block)
59
+ return yield unless operation.dependency
68
60
 
69
- lock_options = LOCK_OPTIONS.merge(:node => master_node)
70
- mutex = Promiscuous::Redis::Mutex.new(instance_dep.key(:sub).to_s, lock_options)
61
+ lock_options = LOCK_OPTIONS.merge(:node => operation.dependency.redis_node)
62
+ mutex = Promiscuous::Redis::Mutex.new(operation.dependency.key(:sub).to_s, lock_options)
71
63
 
72
64
  unless mutex.lock
73
65
  raise Promiscuous::Error::LockUnavailable.new(mutex.key)
@@ -86,14 +78,15 @@ class Promiscuous::Subscriber::UnitOfWork
86
78
 
87
79
  # XXX Used for hooking into e.g. by promiscuous-newrelic
88
80
  def execute_operation(operation)
89
- operation.execute
81
+ with_instance_locked_for(operation) do
82
+ operation.execute
83
+ end
90
84
  end
91
85
 
92
86
  def on_message
93
- with_instance_locked do
94
- with_transaction do
95
- self.operations.each { |op| execute_operation(op) if op.model }
96
- end
87
+ # XXX This needs to be done for each operation
88
+ with_transaction do
89
+ self.operations.each { |op| execute_operation(op) if op.model }
97
90
  end
98
91
  message.ack
99
92
  end
@@ -1,3 +1,3 @@
1
1
  module Promiscuous
2
- VERSION = '0.100.2'
2
+ VERSION = '0.100.3'
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.100.2
4
+ version: 0.100.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Viennot
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-02 00:00:00.000000000 Z
12
+ date: 2014-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport