multithink 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,20 +6,44 @@ include RethinkDB::Shortcuts
6
6
 
7
7
  class MultiThink::Connection
8
8
 
9
- def initialize(servers)
9
+ DEFAULTS = {retries: 10}
10
+
11
+ def initialize(servers, options = {})
10
12
  @servers = servers
13
+ options = DEFAULTS.merge(options)
14
+ @retries = options.fetch(:retries)
11
15
  connect
12
16
  end
13
17
 
14
18
  def connect
15
19
  # TODO try all servers until we get a connection
16
20
  options = @servers.first
17
- @conn = r.connect(options)
21
+ begin
22
+ @conn = r.connect(options)
23
+ rescue
24
+ @tried ||= 0
25
+ sleep 1
26
+ retry if (@tried += 1) < @retries
27
+ end
18
28
  end
19
29
 
20
30
  def run(query)
21
31
  # TODO handle connection failure
22
- query.run(@conn)
32
+ begin
33
+ query.run(@conn)
34
+ rescue RuntimeError => e
35
+ reconnect
36
+ end
37
+ end
38
+
39
+ def reconnect
40
+ begin
41
+ # try fast path first
42
+ @conn.reconnect
43
+ rescue
44
+ # if that fails then try get a new connection
45
+ connect
46
+ end
23
47
  end
24
48
 
25
49
  end
@@ -1,3 +1,3 @@
1
1
  class MultiThink
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multithink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: