mysql_framework 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 089e9d32caf37e266ed17f4c366511814de266b3feaeed97c24781e4f7989de0
4
- data.tar.gz: b566cdb40dc0466cc4b2878cc0e994fc252131350e79467e83e32b608717293e
3
+ metadata.gz: 4cd76e0de90b8c56e1ae4d941f054b34d578e60a98bfc0e81edc37027610ae7b
4
+ data.tar.gz: b3059ba0eb90274b18211fc5efcf6a01a7eb6ad68c7397fbfa7964747638dd37
5
5
  SHA512:
6
- metadata.gz: 39624dce18fedfc9cc8664c9428bd431fd4f7a773239b7cac6e22cba403c2d839809b55ac82dc12c7f81685f3dbd060f00eda2542db3b871499278a2188f328c
7
- data.tar.gz: 21f989dec1fd8399d119e50f038b18679361f924919151d36258468670955712d376c7bb0d928af12a1d60eab7cecae62af9111879dd191a371c7aa1b7420c0a
6
+ metadata.gz: 38d21a76909ce03ba7877483b6aa588a651a52839d9e2339e7700f71913173267c725577591e5767b9e9014ce14437d2518757beffbfba67bc8595f2329277d2
7
+ data.tar.gz: 0429588b4d222a0c361d1516ad5ec89118787f284e79c242bd506e60c9fa132a673637cd06e183809c1d03a0ae7fdd12bcc7ee193d7d939eef9f20b25ed8d98c
@@ -12,7 +12,7 @@ module MysqlFramework
12
12
  def setup
13
13
  @connection_pool = ::Queue.new
14
14
 
15
- start_pool_size.times { @connection_pool.push(Mysql2::Client.new(@options)) }
15
+ start_pool_size.times { @connection_pool.push(new_client) }
16
16
 
17
17
  @created_connections = start_pool_size
18
18
  end
@@ -36,12 +36,17 @@ module MysqlFramework
36
36
 
37
37
  # This method is called to fetch a client from the connection pool.
38
38
  def check_out
39
- @connection_pool.pop(true)
39
+ client = @connection_pool.pop(true)
40
+
41
+ # Prevent "mysql server has gone away" errors by detecting dead clients and creating a new one instead.
42
+ client = new_client if client.closed?
43
+
44
+ client
40
45
  rescue ThreadError
41
46
  if @created_connections < max_pool_size
42
- conn = Mysql2::Client.new(@options)
47
+ client = new_client
43
48
  @created_connections += 1
44
- return conn
49
+ return client
45
50
  end
46
51
 
47
52
  MysqlFramework.logger.error { "[#{self.class}] - Database connection pool depleted." }
@@ -116,6 +121,10 @@ module MysqlFramework
116
121
  }
117
122
  end
118
123
 
124
+ def new_client
125
+ Mysql2::Client.new(@options)
126
+ end
127
+
119
128
  def start_pool_size
120
129
  @start_pool_size ||= Integer(ENV.fetch('MYSQL_START_POOL_SIZE', 1))
121
130
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MysqlFramework
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
@@ -23,7 +23,7 @@ describe MysqlFramework::Connector do
23
23
  reconnect: false
24
24
  }
25
25
  end
26
- let(:client) { double(close: true) }
26
+ let(:client) { double(close: true, closed?: false) }
27
27
  let(:gems) { MysqlFramework::SqlTable.new('gems') }
28
28
  let(:existing_client) { Mysql2::Client.new(default_options) }
29
29
 
@@ -90,6 +90,20 @@ describe MysqlFramework::Connector do
90
90
  end
91
91
  end
92
92
 
93
+ context '' do
94
+ let(:closed_client) { double(close: true, closed?: true) }
95
+
96
+ before do
97
+ subject.connections.clear
98
+ subject.connections.push(closed_client)
99
+ end
100
+
101
+ it 'instantiates a new connection and returns it' do
102
+ expect(Mysql2::Client).to receive(:new).with(default_options).and_return(client)
103
+ expect(subject.check_out).to eq(client)
104
+ end
105
+ end
106
+
93
107
  context "when there are no available connections, and the pool's max size has not been reached" do
94
108
  before do
95
109
  subject.connections.clear
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler