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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 368ce7905399540774509d817b8c0c8fc0710edc
4
- data.tar.gz: 2cf36a5eee9b18be8ca0bcd5c800349735823026
3
+ metadata.gz: 0fb621dfc6b34d3974b40b76e7a2ceaabb154034
4
+ data.tar.gz: 2d11f31335d790eab2995c7bbfe87a401e559808
5
5
  SHA512:
6
- metadata.gz: 8dd1f3b3e00881524e0d7914c6b89724bf7997e87f11a3da7b82374ccaea528d7082802b13370bfa3a720f95eb5fd5d093c3149f77ac927a477619fa65ff02b3
7
- data.tar.gz: ca55fdadff3d4beea31280c5699e48eb18a735dbb0a44e4c67925edf10e618a6aefdbcfe59d4c2909dfc002ccfc7cdcdb7fa509212faae2fbea735e11ce95980
6
+ metadata.gz: 494b6dbb531808a913cdcfa9a21b71ff069ce16ed8c81b80494038d466448569b50ba4b3d783ec879720db36422b260eaad4485b8d546973be4de1b0aa6de349
7
+ data.tar.gz: 27820fe5693a86b97576f31a9932a106e2f89405e1c1d9b859bc4680f392a61c23a95913eb5f6d2728966dd3e7d6b4cc2beb8f5d7b007fec9d59e308f964a611
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.19
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
- @r = @collection.find({_id: @doc_id}).limit(1).first
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
- @collection.find({'_id' => @doc_id}).find_one_and_replace(hash, :upsert => :true)
122
- @r = hash
136
+ @s.synchronize {
137
+ @r = hash
138
+ }
139
+ # The store is made in a separate thread
123
140
  end
124
141
 
125
142
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutella_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.19
4
+ version: 0.4.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Gnoli