reconnection_pool 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/reconnection_pool.rb +65 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3ac4798741cc7b29efb65cb0cb79e7265b828a34
|
4
|
+
data.tar.gz: 8c8bdf6cc7f78d72415362a43fad060a81edd3b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d31308b1b20332c3c832f4257997b4cc437347361f65f840db65278a824820509a4500c20a83272b516c93a142b5d3844e5657dc68c0a96acd1a5f3340e1c168
|
7
|
+
data.tar.gz: e02409029fda7f8db9a6f13a668367569a709d90c6d5389da405ab3458779b9bc5036476a4ea9c94c5e90099d10da2ec55136b82156f518b56eea26634b0b4f1
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class ReconnectionPool
|
2
|
+
class << self
|
3
|
+
include RethinkDB::Shortcuts
|
4
|
+
|
5
|
+
def connect(options)
|
6
|
+
@pool ||= Queue.new
|
7
|
+
@options = set_default_options(options)
|
8
|
+
|
9
|
+
@options[:pool].times do
|
10
|
+
@pool << r.connect(
|
11
|
+
host: @options[:host],
|
12
|
+
port: @options[:port],
|
13
|
+
db: @options[:db],
|
14
|
+
auth_key: @options[:auth_key]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_default_options(options)
|
20
|
+
options.tap do |o|
|
21
|
+
o[:pool] ||= 1
|
22
|
+
o[:host] ||= 'localhost'
|
23
|
+
o[:port] ||= 28015
|
24
|
+
o[:db] ||= 'test'
|
25
|
+
o[:auth_key] ||= nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def return(conn)
|
30
|
+
@pool << conn
|
31
|
+
end
|
32
|
+
|
33
|
+
def get
|
34
|
+
conn = @pool.pop
|
35
|
+
if conn.closed?
|
36
|
+
#If the database goes down, you need to be sure that the object knows its state
|
37
|
+
conn.close
|
38
|
+
begin
|
39
|
+
#It keeps the last configuration used
|
40
|
+
conn.connect
|
41
|
+
rescue Errno::ECONNREFUSED
|
42
|
+
# Just loggin', nothing more to do in this case
|
43
|
+
p "Can't connect to the database"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
conn
|
48
|
+
end
|
49
|
+
|
50
|
+
#Executes a query and returns the connection to the database
|
51
|
+
def run(lazy_query)
|
52
|
+
conn = self.get
|
53
|
+
handle = lazy_query.run(conn)
|
54
|
+
|
55
|
+
self.return conn
|
56
|
+
handle
|
57
|
+
end
|
58
|
+
|
59
|
+
def empty?
|
60
|
+
@pool ||= Queue.new
|
61
|
+
|
62
|
+
@pool.empty?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reconnection_pool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ricardo.k.sasaki@gmail.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rethinkdb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
description: A simple Thread Safe Connection Pool for RethinkDB
|
28
|
+
email: ricardo@followit.ninja
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/reconnection_pool.rb
|
34
|
+
homepage: https://rubygems.org/gems/reconnection_pool
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.5.1
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Connection pool for RethinkDB
|
58
|
+
test_files: []
|