oedipus 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -381,6 +381,17 @@ results = sphinx[:articles].multi_search(
381
381
  # }
382
382
  ```
383
383
 
384
+ ## Disconnecting from Sphinx
385
+
386
+ Oedipus will automatically close connections that are idle, so you don't,
387
+ generally speaking, need to close connections manually. However, before
388
+ forking children, for example, it is important to dispose of any open
389
+ resources to avoid sharing resources across processes. To do this:
390
+
391
+ ``` ruby
392
+ Oedipus.connections.each { |key, conn| conn.close }
393
+ ```
394
+
384
395
  ## Running the specs
385
396
 
386
397
  There are both unit tests and integration tests in the specs/ directory. By default they
@@ -102,6 +102,14 @@ module Oedipus
102
102
  @pool.acquire { |conn| conn.execute(sql, *bind_values) }
103
103
  end
104
104
 
105
+ # Disconnect from the remote host.
106
+ #
107
+ # There is no need to explicitly re-connect after invoking this;
108
+ # connections are re-established as needed.
109
+ def close
110
+ @pool.dispose
111
+ end
112
+
105
113
  private
106
114
 
107
115
  def assert_valid_pool
@@ -70,6 +70,30 @@ module Oedipus
70
70
  release(instance)
71
71
  end
72
72
 
73
+ # Dispose all connections in the pool.
74
+ #
75
+ # Waits until all connections have finished processing current queries
76
+ # and then releases them.
77
+ def dispose
78
+ begin
79
+ @lock.synchronize do
80
+ while instance = @available.pop
81
+ instance.close
82
+ end
83
+
84
+ @condition.wait(@lock) if @used.size > 0
85
+ end
86
+ end until empty?
87
+ end
88
+
89
+ # Returns true if the pool is currently empty.
90
+ #
91
+ # @return [Boolean]
92
+ # true if no connections are pooled, false otherwise
93
+ def empty?
94
+ @lock.synchronize { @used.size == 0 && @available.size == 0 }
95
+ end
96
+
73
97
  private
74
98
 
75
99
  def release(instance)
@@ -8,5 +8,5 @@
8
8
  ##
9
9
 
10
10
  module Oedipus
11
- VERSION = "0.0.14"
11
+ VERSION = "0.0.15"
12
12
  end
@@ -152,4 +152,12 @@ describe Oedipus::Connection do
152
152
  conn.execute("REPLACE INTO posts_rt (id, title, state, body) VALUES (?, 'question?', 'other?', ?)", 1, 'a' * 2_000_000)
153
153
  end
154
154
  end
155
+
156
+ describe "#close" do
157
+ before(:each) { conn.close }
158
+
159
+ it "disposes the internal pool" do
160
+ conn.instance_variable_get(:@pool).should be_empty
161
+ end
162
+ end
155
163
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oedipus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &12537160 !ruby/object:Gem::Requirement
16
+ requirement: &20925980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *12537160
24
+ version_requirements: *20925980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake-compiler
27
- requirement: &12535680 !ruby/object:Gem::Requirement
27
+ requirement: &20925400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12535680
35
+ version_requirements: *20925400
36
36
  description: ! "== Sphinx 2 Comes to Ruby\n\nOedipus brings full support for Sphinx
37
37
  2 to Ruby:\n\n - real-time indexes (insert, replace, update, delete)\n - faceted
38
38
  search (variations on a base query)\n - multi-queries (multiple queries executed
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  segments:
115
115
  - 0
116
- hash: -1945313164651030981
116
+ hash: 1288054359540287220
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements:
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: -1945313164651030981
125
+ hash: 1288054359540287220
126
126
  requirements: []
127
127
  rubyforge_project: oedipus
128
128
  rubygems_version: 1.8.11