em_mysql2_connection_pool 0.0.6 → 0.0.7
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 +4 -4
- data/lib/em_mysql2_connection_pool.rb +17 -17
- data/lib/em_mysql2_connection_pool/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb2177fffa62cf3a77f623977d375d2ed940514
|
4
|
+
data.tar.gz: 228676bf632e16f3d1c1574ebaa9e7f9565f2c1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15071f9295f6790d7164fa175becea1b94a207294ef182933c0fb59ec4d7a8071705fe25c48c854e502a1a6147e6b300ba7c33d6f66d98c396412820baed1731
|
7
|
+
data.tar.gz: fa493766791f19eaed365b3f7e99bc3749d143f801d3fc2ec2ccb65080da4e94f812481c4fc76880c930b4d0fb253ab7de5dd338dfaa7bca928fbc210b39e954
|
@@ -2,36 +2,36 @@ require 'mysql2'
|
|
2
2
|
require 'mysql2/em'
|
3
3
|
|
4
4
|
class EmMysql2ConnectionPool
|
5
|
-
|
5
|
+
|
6
6
|
class Query
|
7
7
|
def initialize(sql, opts, deferrable)
|
8
8
|
@sql, @opts, @deferrable = sql, opts, deferrable
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def sql(connection)
|
12
12
|
@sql.respond_to?(:call) ? @sql.call(connection) : @sql
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def execute(connection, &block)
|
16
16
|
@busy = true
|
17
17
|
@query_text = sql(connection)
|
18
18
|
q = connection.query @query_text, @opts
|
19
19
|
q.callback{ |result| succeed result, connection.affected_rows, &block }
|
20
|
-
q.errback{ |error|
|
20
|
+
q.errback{ |error| fail error, &block }
|
21
21
|
return q
|
22
22
|
rescue StandardError => error
|
23
23
|
fail error, &block
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def succeed(result, affected_rows, &block)
|
27
27
|
@deferrable.succeed result, affected_rows
|
28
28
|
rescue StandardError => error
|
29
|
-
fail error
|
29
|
+
fail error, &block
|
30
30
|
ensure
|
31
31
|
@busy and block and block.call
|
32
32
|
@busy = false
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def fail(error, &block)
|
36
36
|
@deferrable.errback &default_errback unless has_errbacks?
|
37
37
|
@deferrable.fail error, @query_text
|
@@ -39,28 +39,28 @@ class EmMysql2ConnectionPool
|
|
39
39
|
@busy and block and block.call
|
40
40
|
@busy = false
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def has_errbacks?
|
44
44
|
!@deferrable.errbacks.nil?
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def default_errback
|
48
48
|
proc{ |error, sql| puts "#{error.class}: '#{error.message}' with query #{sql} in #{error.backtrace.first}" }
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def initialize(conf)
|
54
54
|
@pool_size = conf[:size] || 10
|
55
55
|
@on_error = conf[:on_error]
|
56
56
|
@query_queue = EM::Queue.new
|
57
57
|
start_queue conf
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def query_backlog
|
61
61
|
@query_queue.size
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def worker
|
65
65
|
proc{ |connection|
|
66
66
|
@query_queue.pop do |query|
|
@@ -68,22 +68,22 @@ class EmMysql2ConnectionPool
|
|
68
68
|
end
|
69
69
|
}
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def start_queue(conf)
|
73
73
|
@pool_size.times do
|
74
74
|
worker.call Mysql2::EM::Client.new conf
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def on_error(&block)
|
79
79
|
@on_error = block
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def query(sql, opts={})
|
83
83
|
deferrable = EM::DefaultDeferrableWithErrbacksAccessor.new
|
84
84
|
deferrable.callback{ |result,affected_rows| yield result, affected_rows } if block_given?
|
85
85
|
deferrable.errback &@on_error if @on_error
|
86
|
-
|
86
|
+
|
87
87
|
@query_queue.push Query.new(sql, opts, deferrable)
|
88
88
|
deferrable
|
89
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em_mysql2_connection_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niko Dittmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project: em_mysql2_connection_pool
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.6.8
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: a simple connection pool for Mysql2::EM connections
|