relaxdb 0.5.1 → 0.5.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.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'spec/rake/spectask'
4
4
 
5
5
  PLUGIN = "relaxdb"
6
6
  NAME = "relaxdb"
7
- GEM_VERSION = "0.5"
7
+ GEM_VERSION = "0.5.2"
8
8
  AUTHOR = "Paul Carey"
9
9
  EMAIL = "paul.p.carey@gmail.com"
10
10
  HOMEPAGE = "http://github.com/paulcarey/relaxdb/"
@@ -1,12 +1,25 @@
1
1
  module RelaxDB
2
2
 
3
3
  class Server
4
+
5
+ attr_reader :host, :port
4
6
 
5
7
  def initialize(host, port)
6
8
  @host = host
7
9
  @port = port
8
10
  end
9
-
11
+
12
+ def cx
13
+ unless @cx && @cx.active?
14
+ @cx = Net::HTTP.start(@host, @port)
15
+ end
16
+ @cx
17
+ end
18
+
19
+ def close_connection
20
+ @cx.finish if @cx
21
+ end
22
+
10
23
  def delete(uri)
11
24
  request(Net::HTTP::Delete.new(uri))
12
25
  end
@@ -30,14 +43,18 @@ module RelaxDB
30
43
  end
31
44
 
32
45
  def request(req)
33
- res = Net::HTTP.start(@host, @port) {|http|
34
- http.request(req)
35
- }
46
+ begin
47
+ res = cx.request(req)
48
+ rescue
49
+ @cx = nil
50
+ res = cx.request(req)
51
+ end
52
+
36
53
  if (not res.kind_of?(Net::HTTPSuccess))
37
54
  handle_error(req, res)
38
55
  end
39
56
  res
40
- end
57
+ end
41
58
 
42
59
  def to_s
43
60
  "http://#{@host}:#{@port}/"
@@ -29,6 +29,11 @@ module RelaxDB
29
29
 
30
30
  # URL encode slashes e.g. RelaxDB.delete_db "foo%2Fbar"
31
31
  def delete_db(name)
32
+ # Close the http connection as CouchDB will keep a file handle to the db open
33
+ # if the http connection remains open - this will result in CouchDB throwing
34
+ # emfile errors after a significant number of databases are deleted.
35
+ @server.close_connection
36
+
32
37
  @logger.info("Deleting database #{name}")
33
38
  @server.delete("/#{name}")
34
39
  end
@@ -13,6 +13,10 @@ module RelaxDB
13
13
  def initialize(host, port)
14
14
  @host, @port = host, port
15
15
  end
16
+
17
+ def close_connection
18
+ # Impl only in net_http as connections are reused
19
+ end
16
20
 
17
21
  def delete(uri)
18
22
  request(uri, 'delete'){ |c| c.http_delete}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 1
9
- version: 0.5.1
8
+ - 2
9
+ version: 0.5.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Carey
@@ -14,7 +14,7 @@ autorequire: relaxdb
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-04 00:00:00 +01:00
17
+ date: 2010-05-13 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency