mongoid_connection_pool 1.0.2
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/lib/mongoid_connection_pool.rb +3 -0
- data/lib/mongoid_connection_pool/mongoid.rb +11 -0
- data/lib/mongoid_connection_pool/mongoid/config.rb +7 -0
- data/lib/mongoid_connection_pool/mongoid/sessions.rb +51 -0
- data/lib/mongoid_connection_pool/mongoid/sessions/session_pool.rb +235 -0
- data/lib/mongoid_connection_pool/version.rb +3 -0
- data/mongoid_connection_pool.gemspec +26 -0
- data/spec/session_pool_spec.rb +121 -0
- data/spec/spec_helper.rb +53 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzQ5Y2MxMTY1YmMyODFjNTI0YzQ5MDQ4NjhkM2VmNDRiYTExYjY2ZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTMzZTMwYzZjNTlkYTcyMGZjYWJhMTI3ZmNkZDUyNGEwYTMwMzAwNA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzRhMmIwYmY5NmI2YzQ0YzExNzAwMTE4NjA5MjRlMTQ2OTAxMDRhOTU1MzMy
|
10
|
+
ZDA2ZmYzMTc4OGY2NGRmNmVjYWM2MWNmYWUzYWU0YjU5YmI2ZjA5OWM4ZWMw
|
11
|
+
Y2RmNDNjMGExNTAwYTlkZWFhMDBlNzY0MzkzMTI1MmZlNzEzZjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjI1NTkyODUwODQyODgxZTJiMTFjMzViNWIwM2M5OWZjMWQ5YWZmYWExM2Yx
|
14
|
+
MGQzZjEwYjJlMGJjMjM0NjE5ZGYwNTc3YzA5MjEwOWUzZjEyYmIzMWJkZGJm
|
15
|
+
ZGYzNmRiMWQ5ZDhlNDMzN2UxOThhYzJiNmU5ODcyMzYwZTVjMDU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Goff
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# MongoidConnectionPool
|
2
|
+
|
3
|
+
If you have ever use Mongoid in a threaded environment such as Sidekiq
|
4
|
+
with Rubinius or JRuby, you will quickly find out that it is not safe to use Mongoid.
|
5
|
+
|
6
|
+
Mongoid by default gives every thread it's own database connection and doesn't
|
7
|
+
clean up after itself, so these connections remain open.
|
8
|
+
MongoDB will quickly become overloaded and you will no longer be able to connect.
|
9
|
+
Often times MongoDB will also likely crash.
|
10
|
+
|
11
|
+
This gem monkey patches Mongoid (>= 3.1 < 4.0) to add connection pooling.
|
12
|
+
We take over how Mongoid handles it's connections, so there is nothing you need
|
13
|
+
to do to take advantage of it.
|
14
|
+
|
15
|
+
This was originally submitted as a PR to the Mongoid project but was turned down
|
16
|
+
since Moped 2.0(MongoDB database driver used by Mongoid) includes it's own
|
17
|
+
implementation of connection pooling.
|
18
|
+
This is all well and good but it is still as of yet to be released, and won't
|
19
|
+
be supported on Mongoid versions < 4.0 (also unreleased).
|
20
|
+
|
21
|
+
This monkey patche passes all of Mongoid's specs.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'mongoid_connection_pool'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install mongoid_connection_pool
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Just require mongoid_connection_pool AFTER Mongoid. That's it. Easy-peasy.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative 'sessions/session_pool'
|
2
|
+
|
3
|
+
module Mongoid
|
4
|
+
module Sessions
|
5
|
+
class << self
|
6
|
+
def synchronize(&block)
|
7
|
+
@lock ||= Mutex.new
|
8
|
+
@lock.synchronize(&block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def session_pool(name=:default)
|
12
|
+
if !@session_pool || !@session_pool[name]
|
13
|
+
synchronize do
|
14
|
+
@session_pool ||= {}
|
15
|
+
@session_pool[name] ||= SessionPool.new(
|
16
|
+
:size => Config.session_pool_size,
|
17
|
+
:name => name,
|
18
|
+
:checkout_timeout => Config.session_checkout_timeout,
|
19
|
+
:reap_frequency => Config.session_reap_frequency)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@session_pool[name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def disconnect
|
26
|
+
synchronize do
|
27
|
+
session_pool.each {|s| s.disconnect}
|
28
|
+
@session_pool = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_name(name)
|
33
|
+
session_pool(name).session_for_thread(Thread.current) ||
|
34
|
+
session_pool(name).checkout
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_session(name=:default)
|
38
|
+
yield
|
39
|
+
ensure
|
40
|
+
reap_current_session(name)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def reap_current_session(name, thread = Thread.current)
|
46
|
+
session_pool(name).checkin_from_thread thread
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Sessions
|
3
|
+
class SessionPool
|
4
|
+
class Queue
|
5
|
+
class ConnectionTimeoutError < StandardError; end
|
6
|
+
|
7
|
+
def initialize(lock=Monitor.new)
|
8
|
+
@lock = lock
|
9
|
+
@cond = @lock.new_cond
|
10
|
+
@num_waiting = 0
|
11
|
+
@queue = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def any_waiting?
|
15
|
+
synchronize do
|
16
|
+
@num_waiting > 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def num_waiting
|
21
|
+
synchronize do
|
22
|
+
@num_waiting
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add(session)
|
27
|
+
synchronize do
|
28
|
+
@queue.push session
|
29
|
+
@cond.signal
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove
|
34
|
+
synchronize do
|
35
|
+
@queue.shift
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def poll(timeout = nil)
|
40
|
+
synchronize do
|
41
|
+
if timeout
|
42
|
+
no_wait_poll || wait_poll(timeout)
|
43
|
+
else
|
44
|
+
no_wait_poll
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def count
|
50
|
+
@queue.count
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def synchronize(&block)
|
56
|
+
@lock.synchronize(&block)
|
57
|
+
end
|
58
|
+
|
59
|
+
def any?
|
60
|
+
!@queue.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
def can_remove_no_wait?
|
64
|
+
@queue.size > @num_waiting
|
65
|
+
end
|
66
|
+
|
67
|
+
def no_wait_poll
|
68
|
+
remove if can_remove_no_wait?
|
69
|
+
end
|
70
|
+
|
71
|
+
def wait_poll(timeout)
|
72
|
+
@num_waiting += 1
|
73
|
+
|
74
|
+
t0 = Time.now
|
75
|
+
elapsed = 0
|
76
|
+
loop do
|
77
|
+
@cond.wait(timeout - elapsed)
|
78
|
+
|
79
|
+
return remove if any?
|
80
|
+
|
81
|
+
elapsed = Time.now - t0
|
82
|
+
if elapsed >= timeout
|
83
|
+
msg = 'Timed out waiting for database session'
|
84
|
+
raise ConnectionTimeoutError, msg
|
85
|
+
end
|
86
|
+
end
|
87
|
+
ensure
|
88
|
+
@num_waiting -= 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
include MonitorMixin
|
93
|
+
|
94
|
+
attr_reader :sessions, :size, :reaper, :reserved_sessions, :available
|
95
|
+
def initialize(opts={})
|
96
|
+
super()
|
97
|
+
opts[:name] ||= :default
|
98
|
+
|
99
|
+
@reaper = Reaper.new(opts[:reap_frequency] || 10, self)
|
100
|
+
@reaper.run
|
101
|
+
|
102
|
+
@checkout_timeout = opts[:checkout_timeout] || 5
|
103
|
+
|
104
|
+
@size = opts[:size] || 5
|
105
|
+
@name = opts[:name] || :default
|
106
|
+
@sessions = []
|
107
|
+
@reserved_sessions = ThreadSafe::Cache.new(:initial_capacity => @size)
|
108
|
+
@available = Queue.new self
|
109
|
+
end
|
110
|
+
|
111
|
+
def checkout
|
112
|
+
unless (session = session_for_thread(Thread.current))
|
113
|
+
synchronize do
|
114
|
+
session = get_session
|
115
|
+
reserve(session)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
session
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns a session back to the available pool
|
122
|
+
def checkin(session)
|
123
|
+
synchronize do
|
124
|
+
@available.add session
|
125
|
+
release(session)
|
126
|
+
end
|
127
|
+
true
|
128
|
+
end
|
129
|
+
|
130
|
+
def clear(thread=nil)
|
131
|
+
if thread
|
132
|
+
@reserved_sessions.delete(thread) if session_for(thread)
|
133
|
+
@sessions.pop
|
134
|
+
else
|
135
|
+
@reserved_sessions = {}
|
136
|
+
@sessions = []
|
137
|
+
@available = Queue.new self
|
138
|
+
end
|
139
|
+
@reserved_sessions
|
140
|
+
end
|
141
|
+
|
142
|
+
def checkin_from_thread(thread)
|
143
|
+
checkin @reserved_sessions[thread]
|
144
|
+
true
|
145
|
+
end
|
146
|
+
|
147
|
+
def count
|
148
|
+
@available.count
|
149
|
+
end
|
150
|
+
|
151
|
+
def reap
|
152
|
+
@reserved_sessions.keys.each do |thread|
|
153
|
+
session = @reserved_sessions[thread]
|
154
|
+
checkin(session) if thread.stop?
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def session_for_thread(thread)
|
159
|
+
@reserved_sessions[thread]
|
160
|
+
end
|
161
|
+
|
162
|
+
def session_for(thread)
|
163
|
+
@reserved_sessions[thread]
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def reserve(session)
|
170
|
+
@reserved_sessions[current_session_id] = session
|
171
|
+
end
|
172
|
+
|
173
|
+
def current_session_id
|
174
|
+
Thread.current
|
175
|
+
end
|
176
|
+
|
177
|
+
def release(session)
|
178
|
+
thread = if @reserved_sessions[current_session_id] == session
|
179
|
+
current_session_id
|
180
|
+
else
|
181
|
+
@reserved_sessions.keys.find do |k|
|
182
|
+
@reserved_sessions[k] == session
|
183
|
+
end
|
184
|
+
end
|
185
|
+
@reserved_sessions.delete thread if thread
|
186
|
+
end
|
187
|
+
|
188
|
+
def get_session
|
189
|
+
if session = @available.poll
|
190
|
+
session
|
191
|
+
elsif @sessions.size < @size
|
192
|
+
checkout_new_session
|
193
|
+
else
|
194
|
+
@available.poll(@checkout_timeout)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def checkout_new_session
|
199
|
+
session = new_session
|
200
|
+
@sessions << session
|
201
|
+
session
|
202
|
+
end
|
203
|
+
|
204
|
+
def new_session
|
205
|
+
Factory.create(@name)
|
206
|
+
end
|
207
|
+
|
208
|
+
class ConnectionTimeoutError < StandardError; end
|
209
|
+
|
210
|
+
def create_new_session
|
211
|
+
Factory.create(@name)
|
212
|
+
end
|
213
|
+
|
214
|
+
class Reaper
|
215
|
+
attr_reader :pool
|
216
|
+
attr_reader :frequency
|
217
|
+
def initialize(frequency, pool)
|
218
|
+
@frequency = frequency
|
219
|
+
@pool = pool
|
220
|
+
end
|
221
|
+
|
222
|
+
def run
|
223
|
+
return unless frequency
|
224
|
+
Thread.new(frequency, pool) do |t, p|
|
225
|
+
while true
|
226
|
+
sleep t
|
227
|
+
p.reap
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mongoid_connection_pool/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mongoid_connection_pool"
|
8
|
+
spec.version = MongoidConnectionPool::VERSION
|
9
|
+
spec.authors = ["Brian Goff"]
|
10
|
+
spec.email = ["cpuguy83@gmail.com"]
|
11
|
+
spec.description = %q{Provides connection pooling for Mongoid}
|
12
|
+
spec.summary = %q{Provides connection pooling for Mongoid}
|
13
|
+
spec.homepage = "http://www.github.com/cpuguy83/mongoid_connection_pool"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "mongoid", "~> 3.1.0"
|
26
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::Sessions::SessionPool do
|
4
|
+
|
5
|
+
let!(:session_pool) do
|
6
|
+
Mongoid::Sessions.session_pool(:default)
|
7
|
+
end
|
8
|
+
|
9
|
+
let!(:before_run_available_sessions) do
|
10
|
+
session_pool.available
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.checkout' do
|
14
|
+
|
15
|
+
it 'Checks out session from the available pool and put in reserved_sessions' do
|
16
|
+
expect(session_pool.checkout).to be_a(Moped::Session)
|
17
|
+
expect(session_pool.session_for(Thread.current)).
|
18
|
+
to be_a(Moped::Session)
|
19
|
+
|
20
|
+
unless before_run_available_sessions.count == 0
|
21
|
+
expect(session_pool.available.count).
|
22
|
+
to eq (before_run_available_sessions.count - 1)
|
23
|
+
else
|
24
|
+
expect(session_pool.available.count).to eq(0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'When all sessions are checked out' do
|
29
|
+
let(:session_pool) do
|
30
|
+
Mongoid::Sessions::SessionPool.new(
|
31
|
+
size: 0,
|
32
|
+
name: :default,
|
33
|
+
checkout_timeout: 0.001)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'Waits the checkout_timeout period and returns an error' do
|
37
|
+
expect { session_pool.checkout }.
|
38
|
+
to raise_error(Mongoid::Sessions::SessionPool::Queue::ConnectionTimeoutError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '.checkin' do
|
45
|
+
before do
|
46
|
+
session_pool.clear
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:session) do
|
50
|
+
session_pool.checkout
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'Checks a session back into the available pool' do
|
54
|
+
expect(session_pool.checkin(session)).to be true
|
55
|
+
|
56
|
+
expect(session_pool.available.count).to eq 1
|
57
|
+
|
58
|
+
expect(session_pool.session_for(Thread.current)).
|
59
|
+
to be nil
|
60
|
+
|
61
|
+
expect(session_pool.sessions.count).to eq 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '.checkin_from_thread' do
|
66
|
+
let(:session) do
|
67
|
+
session_pool.checkout
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'Checks in the session for the given thread' do
|
71
|
+
expect(session_pool.checkin_from_thread(Thread.current)).
|
72
|
+
to be true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.clear' do
|
77
|
+
before do
|
78
|
+
# Make sure there is something in session.sessions first
|
79
|
+
session_pool.checkout
|
80
|
+
end
|
81
|
+
|
82
|
+
before do
|
83
|
+
session_pool.clear
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'Clears the sessions for the given thread' do
|
87
|
+
expect(session_pool.sessions.count).to be 0
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '.reap' do
|
93
|
+
|
94
|
+
let(:thread) do
|
95
|
+
Thread.new { session_pool.checkout }
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'Reaps sessions from dead/sleeping threads' do
|
99
|
+
thread.join
|
100
|
+
|
101
|
+
expect(session_pool.reap).to be_true
|
102
|
+
|
103
|
+
session_pool.session_for(thread).should be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '.session_for' do
|
109
|
+
|
110
|
+
before do
|
111
|
+
session_pool.clear
|
112
|
+
session_pool.checkout
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'Gets the session for the given thread' do
|
116
|
+
expect(session_pool.session_for(Thread.current)).
|
117
|
+
to be_a Moped::Session
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'mongoid_connection_pool'
|
2
|
+
|
3
|
+
# These environment variables can be set if wanting to test against a database
|
4
|
+
# that is not on the local machine.
|
5
|
+
ENV["MONGOID_SPEC_HOST"] ||= "localhost"
|
6
|
+
ENV["MONGOID_SPEC_PORT"] ||= "27017"
|
7
|
+
|
8
|
+
# These are used when creating any connection in the test suite.
|
9
|
+
HOST = ENV["MONGOID_SPEC_HOST"]
|
10
|
+
PORT = ENV["MONGOID_SPEC_PORT"].to_i
|
11
|
+
|
12
|
+
# Moped.logger.level = Logger::DEBUG
|
13
|
+
# Mongoid.logger.level = Logger::DEBUG
|
14
|
+
|
15
|
+
# When testing locally we use the database named mongoid_test. However when
|
16
|
+
# tests are running in parallel on Travis we need to use different database
|
17
|
+
# names for each process running since we do not have transactions and want a
|
18
|
+
# clean slate before each spec run.
|
19
|
+
def database_id
|
20
|
+
"mongoid_test"
|
21
|
+
end
|
22
|
+
|
23
|
+
def database_id_alt
|
24
|
+
"mongoid_test_alt"
|
25
|
+
end
|
26
|
+
|
27
|
+
CONFIG = {
|
28
|
+
sessions: {
|
29
|
+
default: {
|
30
|
+
database: database_id,
|
31
|
+
hosts: [ "#{HOST}:#{PORT}" ]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
# Can we connect to MongoHQ from this box?
|
37
|
+
def mongohq_connectable?
|
38
|
+
ENV["MONGOHQ_REPL_PASS"].present?
|
39
|
+
end
|
40
|
+
|
41
|
+
def purge_database_alt!
|
42
|
+
session = Mongoid::Sessions.default
|
43
|
+
session.use(database_id_alt)
|
44
|
+
session.collections.each do |collection|
|
45
|
+
collection.drop
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set the database that the spec suite connects to.
|
50
|
+
Mongoid.configure do |config|
|
51
|
+
config.load_configuration(CONFIG)
|
52
|
+
end
|
53
|
+
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_connection_pool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Goff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
prerelease: false
|
16
|
+
type: :development
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
prerelease: false
|
30
|
+
type: :development
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: !binary |-
|
36
|
+
MA==
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: !binary |-
|
42
|
+
MA==
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: !binary |-
|
52
|
+
MA==
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: !binary |-
|
58
|
+
MA==
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: mongoid
|
61
|
+
prerelease: false
|
62
|
+
type: :runtime
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.1.0
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.1.0
|
73
|
+
description: Provides connection pooling for Mongoid
|
74
|
+
email:
|
75
|
+
- cpuguy83@gmail.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- lib/mongoid_connection_pool.rb
|
86
|
+
- lib/mongoid_connection_pool/mongoid.rb
|
87
|
+
- lib/mongoid_connection_pool/mongoid/config.rb
|
88
|
+
- lib/mongoid_connection_pool/mongoid/sessions.rb
|
89
|
+
- lib/mongoid_connection_pool/mongoid/sessions/session_pool.rb
|
90
|
+
- lib/mongoid_connection_pool/version.rb
|
91
|
+
- mongoid_connection_pool.gemspec
|
92
|
+
- spec/session_pool_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
homepage: http://www.github.com/cpuguy83/mongoid_connection_pool
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: !binary |-
|
107
|
+
MA==
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: !binary |-
|
113
|
+
MA==
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.6
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Provides connection pooling for Mongoid
|
120
|
+
test_files:
|
121
|
+
- spec/session_pool_spec.rb
|
122
|
+
- spec/spec_helper.rb
|