qu-mongo 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/qu/backend/mongo.rb +28 -1
- metadata +7 -7
data/lib/qu/backend/mongo.rb
CHANGED
@@ -3,6 +3,18 @@ require 'mongo'
|
|
3
3
|
module Qu
|
4
4
|
module Backend
|
5
5
|
class Mongo < Base
|
6
|
+
|
7
|
+
# Number of times to retry connection on connection failure (default: 5)
|
8
|
+
attr_accessor :max_retries
|
9
|
+
|
10
|
+
# Seconds to wait before try to reconnect after connection failure (default: 1)
|
11
|
+
attr_accessor :retry_frequency
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
self.max_retries = 5
|
15
|
+
self.retry_frequency = 1
|
16
|
+
end
|
17
|
+
|
6
18
|
def connection
|
7
19
|
@connection ||= begin
|
8
20
|
uri = URI.parse(ENV['MONGOHQ_URL'].to_s)
|
@@ -118,8 +130,23 @@ module Qu
|
|
118
130
|
end
|
119
131
|
|
120
132
|
def [](name)
|
121
|
-
|
133
|
+
rescue_connection_failure do
|
134
|
+
database["qu:#{name}"]
|
135
|
+
end
|
122
136
|
end
|
137
|
+
|
138
|
+
def rescue_connection_failure
|
139
|
+
retries = 0
|
140
|
+
begin
|
141
|
+
yield
|
142
|
+
rescue ::Mongo::ConnectionFailure => ex
|
143
|
+
retries += 1
|
144
|
+
raise ex if retries > max_retries
|
145
|
+
sleep(retry_frequency * retries)
|
146
|
+
retry
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
123
150
|
end
|
124
151
|
end
|
125
152
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qu-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Keepers
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -40,12 +40,12 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - "="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 29
|
44
44
|
segments:
|
45
45
|
- 0
|
46
46
|
- 1
|
47
|
-
-
|
48
|
-
version: 0.1.
|
47
|
+
- 3
|
48
|
+
version: 0.1.3
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|