ruote-ar 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruote/ar/storage.rb +9 -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: d64ffb7cb111a0d9c00a7f815ee5f04df9160349
|
4
|
+
data.tar.gz: f52106125bb89b301673c239de8f4d58e731af68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33be828e28671f0e83efbdd47b16948ac6f90fdfa96fb93e25a70cb7b4e80273c63970d80ea753f513b4406a331dd747c3db553a4191cb55ad37010ffcbe5692
|
7
|
+
data.tar.gz: 1b73c6f25e2bb5b3e8a7d227513c656121c7096b1c727f2324065be4958ffdd6e1a4c2be750c9d961e280ba327852a533d47c1852ae12dd84ab83fa6c6a3f850
|
data/lib/ruote/ar/storage.rb
CHANGED
@@ -34,6 +34,10 @@ module Ruote
|
|
34
34
|
# return true if the update was affected more than one line.
|
35
35
|
#
|
36
36
|
def reserve(doc)
|
37
|
+
# doc is already this worker
|
38
|
+
return true if !doc['_worker'].nil? && doc['_worker'] == @worker
|
39
|
+
|
40
|
+
# try reserve this document
|
37
41
|
um = Arel::UpdateManager.new Arel::Table.engine
|
38
42
|
um.table table
|
39
43
|
um.where table[:typ].eq(doc['type'].to_s).
|
@@ -130,8 +134,8 @@ module Ruote
|
|
130
134
|
|
131
135
|
keys = key ? Array(key) : nil
|
132
136
|
ds = ds.and(table[:wfid].in(keys)) if keys && keys.first.is_a?(String)
|
133
|
-
ds = ds.and(table[:worker].eq(nil)) if type == 'msgs'
|
134
|
-
|
137
|
+
ds = ds.and(table[:worker].eq(nil).or(table[:worker].eq(@worker))) if type == 'msgs'
|
138
|
+
|
135
139
|
ds = table.where(ds)
|
136
140
|
|
137
141
|
return connection.select_value(ds.project(table[:wfid].count)) if opts[:count]
|
@@ -150,7 +154,9 @@ module Ruote
|
|
150
154
|
|
151
155
|
docs = connection.select_all(ds.project('*'))
|
152
156
|
docs = select_last_revs(docs)
|
153
|
-
|
157
|
+
|
158
|
+
# TIP: append worker info to doc to use in reserve
|
159
|
+
docs = docs.collect { |d| Rufus::Json.decode(d['doc']).merge({'_worker' => d['worker']}) }
|
154
160
|
|
155
161
|
if keys && keys.first.is_a?(Regexp)
|
156
162
|
docs.select { |doc| keys.find { |k| k.match(doc['_id']) } }
|