promiscuous 0.100.2 → 0.100.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 661ee6c4ebf5e97d57ba23bc894dec27875b51da
|
4
|
+
data.tar.gz: 0c803f496368153a921f2e1a377f8164c65574b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62dce82bf3dae1f68f6fdeb895059162c3e66e82587096a6b2d6ee6ebd6a1bbbae4cdcb95cb19e417ac4b712a33785e39521206f1206f33f3559a30c55e60b79
|
7
|
+
data.tar.gz: 90926a0597ef13645fdb17aeca623f28fe57bf6101208d73f529c82812162ce133a8893411a93c3392c24832b343d6423a5db82640379f942757b7aea6efca57
|
@@ -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, :
|
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.
|
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('
|
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
|
67
|
-
return yield unless
|
58
|
+
def with_instance_locked_for(operation, &block)
|
59
|
+
return yield unless operation.dependency
|
68
60
|
|
69
|
-
lock_options = LOCK_OPTIONS.merge(:node =>
|
70
|
-
mutex = Promiscuous::Redis::Mutex.new(
|
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
|
81
|
+
with_instance_locked_for(operation) do
|
82
|
+
operation.execute
|
83
|
+
end
|
90
84
|
end
|
91
85
|
|
92
86
|
def on_message
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
data/lib/promiscuous/version.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: 0.100.
|
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-
|
12
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|