ruote-ar 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ruote/ar/storage.rb +46 -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: beb4c18668af91fa8b6a4ba3a3abed4316e4fe77
|
4
|
+
data.tar.gz: 7a93b743ddb918d27aa1244450df79b8457b6fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac677179ca943b539c4968729252b128b93a03c99b2527b076dcc068d73f0d78a05e6a773b981b8b18680a0ce0f5f482709fb01e9c60051c984970be1742fa19
|
7
|
+
data.tar.gz: bda0a68ab0aea9c55e794c3f58a97c6197219ea8137c8c22e5878b738ee12172a5d820d7c4ef55e6cd16287e9ec6e060ea0006bcc85b5c2c1865c362a084e9c2
|
data/lib/ruote/ar/storage.rb
CHANGED
@@ -14,6 +14,8 @@ module Ruote
|
|
14
14
|
|
15
15
|
@table_name = options['table_name'] || ('documents').to_sym
|
16
16
|
@ip = Ruote.local_ip
|
17
|
+
@last_time = Time.at(0.0).utc
|
18
|
+
|
17
19
|
@worker = [current_worker_name, @ip.gsub(/\./, '_'), $$.to_s].join('/')
|
18
20
|
|
19
21
|
replace_engine_configuration(options)
|
@@ -28,19 +30,50 @@ module Ruote
|
|
28
30
|
nil
|
29
31
|
end
|
30
32
|
|
33
|
+
def begin_step
|
34
|
+
|
35
|
+
# release uncommited releases
|
36
|
+
connection.execute("ROLLBACK")
|
37
|
+
|
38
|
+
now = Time.now.utc
|
39
|
+
delta = now - @last_time
|
40
|
+
|
41
|
+
# just try release locked documents each 20 seconds
|
42
|
+
return if delta < 30
|
43
|
+
|
44
|
+
@last_time = now
|
45
|
+
|
46
|
+
# release all locked msgs
|
47
|
+
um = Arel::UpdateManager.new Arel::Table.engine
|
48
|
+
um.table table
|
49
|
+
um.where table[:typ].eq('msgs').and(table[:worker].eq(@worker))
|
50
|
+
um.set [
|
51
|
+
[table[:worker], nil]
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
31
55
|
# Used to reserve 'msgs' and 'schedules'. Simply update and
|
32
56
|
# return true if the update was affected more than one line.
|
33
57
|
#
|
34
58
|
def reserve(doc)
|
35
59
|
um = Arel::UpdateManager.new Arel::Table.engine
|
36
60
|
um.table table
|
37
|
-
um.where table[:typ].eq(doc['type'].to_s).
|
61
|
+
um.where table[:typ].eq(doc['type'].to_s).
|
62
|
+
and(table[:ide].eq(doc['_id'].to_s).
|
63
|
+
and(table[:rev].eq(1).
|
64
|
+
and(table[:worker].eq(nil))))
|
38
65
|
um.set [
|
39
66
|
[table[:worker], @worker]
|
40
67
|
]
|
41
|
-
connection.update(um.to_sql) > 0
|
68
|
+
if connection.update(um.to_sql) > 0
|
69
|
+
begin_transaction
|
70
|
+
true
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
42
74
|
end
|
43
75
|
|
76
|
+
|
44
77
|
# removing doc after success (or fail) success.
|
45
78
|
# It's important to not leave any message.
|
46
79
|
def done(doc)
|
@@ -48,6 +81,8 @@ module Ruote
|
|
48
81
|
dm.from table
|
49
82
|
dm.where table[:typ].eq(doc['type']).and(table[:ide].eq(doc['_id']).and(table[:rev].eq(1).and(table[:worker].eq(@worker))))
|
50
83
|
connection.delete(dm)
|
84
|
+
|
85
|
+
commit
|
51
86
|
end
|
52
87
|
|
53
88
|
def put_schedule(flavour, owner_fei, s, msg)
|
@@ -330,7 +365,15 @@ module Ruote
|
|
330
365
|
worker = Thread.current['ruote_worker']
|
331
366
|
if worker
|
332
367
|
worker.name
|
333
|
-
end ||
|
368
|
+
end || "worker"
|
369
|
+
end
|
370
|
+
|
371
|
+
def begin_transaction
|
372
|
+
connection.execute("BEGIN")
|
373
|
+
end
|
374
|
+
|
375
|
+
def commit
|
376
|
+
connection.execute("COMMIT")
|
334
377
|
end
|
335
378
|
|
336
379
|
end
|