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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruote/ar/storage.rb +46 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45956b7a81783e00454f1e1fe081c4de7d498b28
4
- data.tar.gz: 297fa1eead0ae45858a6716f1a0165bbc3a49fd4
3
+ metadata.gz: beb4c18668af91fa8b6a4ba3a3abed4316e4fe77
4
+ data.tar.gz: 7a93b743ddb918d27aa1244450df79b8457b6fc7
5
5
  SHA512:
6
- metadata.gz: 6dfeb77f03e9336c843b4ebcc47dcf7fdf5725bc35855f333397723871c61037c8a0755d12b4bacc352c07bc4421bb490f0714404334fb076aad47bec84c827d
7
- data.tar.gz: 15b4c571acf51b7a4f4adaab89e34831ee0b922c30d23f6a4f8f9f3fc7335f88f8819310b070647d97d654e41f0d24553c2d5ab4826a16ab7e6496e03bae9df1
6
+ metadata.gz: ac677179ca943b539c4968729252b128b93a03c99b2527b076dcc068d73f0d78a05e6a773b981b8b18680a0ce0f5f482709fb01e9c60051c984970be1742fa19
7
+ data.tar.gz: bda0a68ab0aea9c55e794c3f58a97c6197219ea8137c8c22e5878b738ee12172a5d820d7c4ef55e6cd16287e9ec6e060ea0006bcc85b5c2c1865c362a084e9c2
@@ -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).and(table[:ide].eq(doc['_id'].to_s).and(table[:rev].eq(1).and(table[:worker].eq(nil))))
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 || 'worker'
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
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - pedroteixeira