nutella_lib 0.4.19 → 0.4.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/util/mongo_persisted_hash.rb +20 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fb621dfc6b34d3974b40b76e7a2ceaabb154034
|
4
|
+
data.tar.gz: 2d11f31335d790eab2995c7bbfe87a401e559808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 494b6dbb531808a913cdcfa9a21b71ff069ce16ed8c81b80494038d466448569b50ba4b3d783ec879720db36422b260eaad4485b8d546973be4de1b0aa6de349
|
7
|
+
data.tar.gz: 27820fe5693a86b97576f31a9932a106e2f89405e1c1d9b859bc4680f392a61c23a95913eb5f6d2728966dd3e7d6b4cc2beb8f5d7b007fec9d59e308f964a611
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.20
|
@@ -18,6 +18,19 @@ class MongoPersistedHash
|
|
18
18
|
client = Mongo::Client.new([hostname], :database => db)
|
19
19
|
@collection = client[collection]
|
20
20
|
@doc_id = name
|
21
|
+
|
22
|
+
# Semaphore for the write on DB synchronization
|
23
|
+
@s = Mutex.new
|
24
|
+
|
25
|
+
Thread.new {
|
26
|
+
while sleep 1
|
27
|
+
@s.synchronize {
|
28
|
+
if(!defined? @r)
|
29
|
+
@collection.find({'_id' => @doc_id}).find_one_and_replace(@r, :upsert => :true)
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
}
|
21
34
|
end
|
22
35
|
|
23
36
|
|
@@ -111,15 +124,19 @@ class MongoPersistedHash
|
|
111
124
|
|
112
125
|
def load_hash
|
113
126
|
if(!defined? @r)
|
114
|
-
@
|
127
|
+
@s.synchronize {
|
128
|
+
@r = @collection.find({_id: @doc_id}).limit(1).first
|
129
|
+
}
|
115
130
|
end
|
116
131
|
@r.nil? ? {'_id' => @doc_id} : @r
|
117
132
|
end
|
118
133
|
|
119
134
|
|
120
135
|
def store_hash(hash)
|
121
|
-
@
|
122
|
-
|
136
|
+
@s.synchronize {
|
137
|
+
@r = hash
|
138
|
+
}
|
139
|
+
# The store is made in a separate thread
|
123
140
|
end
|
124
141
|
|
125
142
|
|