ruote-ar 0.0.5 → 0.0.6
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 +8 -92
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45956b7a81783e00454f1e1fe081c4de7d498b28
|
4
|
+
data.tar.gz: 297fa1eead0ae45858a6716f1a0165bbc3a49fd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfeb77f03e9336c843b4ebcc47dcf7fdf5725bc35855f333397723871c61037c8a0755d12b4bacc352c07bc4421bb490f0714404334fb076aad47bec84c827d
|
7
|
+
data.tar.gz: 15b4c571acf51b7a4f4adaab89e34831ee0b922c30d23f6a4f8f9f3fc7335f88f8819310b070647d97d654e41f0d24553c2d5ab4826a16ab7e6496e03bae9df1
|
data/lib/ruote/ar/storage.rb
CHANGED
@@ -13,6 +13,8 @@ module Ruote
|
|
13
13
|
def initialize(options = {})
|
14
14
|
|
15
15
|
@table_name = options['table_name'] || ('documents').to_sym
|
16
|
+
@ip = Ruote.local_ip
|
17
|
+
@worker = [current_worker_name, @ip.gsub(/\./, '_'), $$.to_s].join('/')
|
16
18
|
|
17
19
|
replace_engine_configuration(options)
|
18
20
|
end
|
@@ -34,7 +36,7 @@ module Ruote
|
|
34
36
|
um.table table
|
35
37
|
um.where table[:typ].eq(doc['type'].to_s).and(table[:ide].eq(doc['_id'].to_s).and(table[:rev].eq(1).and(table[:worker].eq(nil))))
|
36
38
|
um.set [
|
37
|
-
[table[:worker], worker]
|
39
|
+
[table[:worker], @worker]
|
38
40
|
]
|
39
41
|
connection.update(um.to_sql) > 0
|
40
42
|
end
|
@@ -44,7 +46,7 @@ module Ruote
|
|
44
46
|
def done(doc)
|
45
47
|
dm = Arel::DeleteManager.new Arel::Table.engine
|
46
48
|
dm.from table
|
47
|
-
dm.where table[:typ].eq(doc['type']).and(table[:ide].eq(doc['_id']).and(table[:rev].eq(1).and(table[:worker].eq(worker))))
|
49
|
+
dm.where table[:typ].eq(doc['type']).and(table[:ide].eq(doc['_id']).and(table[:rev].eq(1).and(table[:worker].eq(@worker))))
|
48
50
|
connection.delete(dm)
|
49
51
|
end
|
50
52
|
|
@@ -63,8 +65,6 @@ module Ruote
|
|
63
65
|
|
64
66
|
def put(doc, opts={})
|
65
67
|
|
66
|
-
cache_clear(doc)
|
67
|
-
|
68
68
|
if doc['_rev']
|
69
69
|
|
70
70
|
d = get(doc['type'], doc['_id'])
|
@@ -96,7 +96,7 @@ module Ruote
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def get(type, key)
|
99
|
-
|
99
|
+
do_get(type, key)
|
100
100
|
end
|
101
101
|
|
102
102
|
def delete(doc)
|
@@ -104,8 +104,7 @@ module Ruote
|
|
104
104
|
|
105
105
|
raise ArgumentError.new('no _rev for doc') unless doc['_rev']
|
106
106
|
|
107
|
-
|
108
|
-
# usually not necessary, adding it not to forget it later on
|
107
|
+
# usually not necessary, adding it not to forget it later on
|
109
108
|
|
110
109
|
dm = Arel::DeleteManager.new Arel::Table.engine
|
111
110
|
dm.from table
|
@@ -121,11 +120,6 @@ module Ruote
|
|
121
120
|
|
122
121
|
def get_many(type, key=nil, opts={})
|
123
122
|
|
124
|
-
###
|
125
|
-
|
126
|
-
cached = cache_get_many(type, key, opts)
|
127
|
-
return cached if cached
|
128
|
-
|
129
123
|
ds = table[:typ].eq(type)
|
130
124
|
|
131
125
|
keys = key ? Array(key) : nil
|
@@ -257,11 +251,6 @@ module Ruote
|
|
257
251
|
select_last_revs(connection.select_all(ds.project('*'))).collect { |d| Ruote::Workitem.from_json(d['doc']) }
|
258
252
|
end
|
259
253
|
|
260
|
-
def begin_step
|
261
|
-
|
262
|
-
prepare_cache
|
263
|
-
end
|
264
|
-
|
265
254
|
protected
|
266
255
|
|
267
256
|
def decode_doc(doc)
|
@@ -328,80 +317,6 @@ module Ruote
|
|
328
317
|
}
|
329
318
|
end
|
330
319
|
|
331
|
-
#--
|
332
|
-
# worker step cache
|
333
|
-
#
|
334
|
-
# in order to cut down the number of selects, do one select with
|
335
|
-
# all the information the worker needs for one step of work
|
336
|
-
#++
|
337
|
-
|
338
|
-
|
339
|
-
CACHED_TYPES = %w[ msgs schedules configurations variables ]
|
340
|
-
|
341
|
-
# One select to grab in all the info necessary for a worker step
|
342
|
-
# (expressions excepted).
|
343
|
-
#
|
344
|
-
def prepare_cache
|
345
|
-
|
346
|
-
CACHED_TYPES.each { |t| cache[t] = {} }
|
347
|
-
|
348
|
-
ds = table.where(table[:typ].in(CACHED_TYPES)).
|
349
|
-
project(table[:ide], table[:typ], table[:doc]).
|
350
|
-
order(table[:ide].asc, table[:rev].desc)
|
351
|
-
|
352
|
-
connection.select_all(ds).each do |d|
|
353
|
-
(cache[d['typ']] ||= {})[d['ide']] ||= decode_doc(d)
|
354
|
-
end
|
355
|
-
|
356
|
-
cache['variables']['trackers'] ||=
|
357
|
-
{ '_id' => 'trackers', 'type' => 'variables', 'trackers' => {} }
|
358
|
-
end
|
359
|
-
|
360
|
-
# Ask the cache for a doc. Returns nil if it's not cached.
|
361
|
-
#
|
362
|
-
def cache_get(type, key)
|
363
|
-
|
364
|
-
(cache[type] || {})[key]
|
365
|
-
end
|
366
|
-
|
367
|
-
# Ask the cache for a set of documents. Returns nil if it's not cached
|
368
|
-
# or caching is not OK.
|
369
|
-
#
|
370
|
-
def cache_get_many(type, keys, options)
|
371
|
-
|
372
|
-
if !options[:batch] && CACHED_TYPES.include?(type) && cache[type]
|
373
|
-
cache[type].values
|
374
|
-
else
|
375
|
-
nil
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
# Removes a document from the cache.
|
380
|
-
#
|
381
|
-
def cache_clear(doc)
|
382
|
-
|
383
|
-
(cache[doc['type']] || {}).delete(doc['_id'])
|
384
|
-
end
|
385
|
-
|
386
|
-
# Returns the cache for the given thread. Returns {} if there is no
|
387
|
-
# cache available.
|
388
|
-
#
|
389
|
-
def cache
|
390
|
-
|
391
|
-
worker = Thread.current['ruote_worker']
|
392
|
-
|
393
|
-
return {} unless worker
|
394
|
-
|
395
|
-
(Thread.current["cache_#{worker.name}"] ||= {})
|
396
|
-
end
|
397
|
-
|
398
|
-
|
399
|
-
# def do_delete(doc)
|
400
|
-
# Document.delete_all(
|
401
|
-
# :ide => doc['_id'], :typ => doc['type'], :rev => doc['_rev'].to_i
|
402
|
-
# )
|
403
|
-
# end
|
404
|
-
|
405
320
|
private
|
406
321
|
def table
|
407
322
|
@table ||= ::Arel::Table.new @table_name
|
@@ -411,12 +326,13 @@ module Ruote
|
|
411
326
|
::ActiveRecord::Base.connection
|
412
327
|
end
|
413
328
|
|
414
|
-
def
|
329
|
+
def current_worker_name
|
415
330
|
worker = Thread.current['ruote_worker']
|
416
331
|
if worker
|
417
332
|
worker.name
|
418
333
|
end || 'worker'
|
419
334
|
end
|
335
|
+
|
420
336
|
end
|
421
337
|
end
|
422
338
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruote-ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pedroteixeira
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|