em-mysqlplus 0.1.4 → 0.1.5
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/VERSION +1 -1
- data/em-mysqlplus.gemspec +4 -4
- data/lib/active_record/connection_adapters/em_mysqlplus_adapter.rb +28 -12
- data/lib/active_record/patches.rb +1 -1
- data/lib/em-mysqlplus/connection.rb +17 -10
- data/spec/activerecord_spec.rb +6 -0
- data/spec/database.yml +1 -1
- metadata +7 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/em-mysqlplus.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{em-mysqlplus}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ilya Grigorik", "Aman Gupta"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-03}
|
13
13
|
s.description = %q{Async MySQL driver for Ruby/Eventmachine}
|
14
14
|
s.email = %q{ilya@igvita.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.rdoc_options = ["--charset=UTF-8"]
|
36
36
|
s.require_paths = ["lib"]
|
37
37
|
s.rubyforge_project = %q{em-mysqlplus}
|
38
|
-
s.rubygems_version = %q{1.3.
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
39
|
s.summary = %q{Async MySQL driver for Ruby/Eventmachine}
|
40
40
|
s.test_files = [
|
41
41
|
"spec/activerecord_spec.rb",
|
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
|
|
47
47
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
48
|
s.specification_version = 3
|
49
49
|
|
50
|
-
if Gem::Version.new(Gem::
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
51
|
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.9"])
|
52
52
|
else
|
53
53
|
s.add_dependency(%q<eventmachine>, [">= 0.12.9"])
|
@@ -15,16 +15,21 @@ module ActiveRecord
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def connect
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
if EM.reactor_running?
|
19
|
+
@connection = EventMachine::MySQL.new({
|
20
|
+
:host => @hostname,
|
21
|
+
:port => @port,
|
22
|
+
:user => @config[:username],
|
23
|
+
:database => @config[:database],
|
24
|
+
:password => @config[:password],
|
25
|
+
:socket => @config[:socket]
|
26
|
+
})
|
27
|
+
|
28
|
+
configure_connection
|
29
|
+
@connection
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
28
33
|
end
|
29
34
|
|
30
35
|
end
|
@@ -44,7 +49,18 @@ module ActiveRecord
|
|
44
49
|
raise ArgumentError, "No database specified. Missing argument: database."
|
45
50
|
end
|
46
51
|
|
47
|
-
|
52
|
+
if EM.reactor_running?
|
53
|
+
ConnectionAdapters::EmMysqlAdapter.new(nil, logger, [host, port], [database, username, password], config)
|
54
|
+
else
|
55
|
+
mysql = Mysql.init
|
56
|
+
if config[:sslca] || config[:sslkey]
|
57
|
+
mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher])
|
58
|
+
end
|
59
|
+
|
60
|
+
default_flags = Mysql.const_defined?(:CLIENT_MULTI_RESULTS) ? Mysql::CLIENT_MULTI_RESULTS : 0
|
61
|
+
options = [host, username, password, database, port, nil, default_flags]
|
62
|
+
ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config)
|
63
|
+
end
|
48
64
|
end
|
49
65
|
end
|
50
|
-
end
|
66
|
+
end
|
@@ -37,6 +37,7 @@ module EventMachine
|
|
37
37
|
if item = @current
|
38
38
|
sql, cblk, eblk, retries = item
|
39
39
|
result = @mysql.get_result
|
40
|
+
result = @mysql.affected_rows if result.nil?
|
40
41
|
|
41
42
|
# kick off next query in the background
|
42
43
|
# as we process the current results
|
@@ -80,18 +81,22 @@ module EventMachine
|
|
80
81
|
# reconnects to happen after all the unbinds have been processed
|
81
82
|
|
82
83
|
@connected = false
|
84
|
+
EM.next_tick { reconnect }
|
85
|
+
end
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
87
|
+
def reconnect
|
88
|
+
@processing = false
|
89
|
+
@mysql = @conn.connect_socket(@opts)
|
90
|
+
@fd = @mysql.socket
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
@signature = EM.attach_fd(@mysql.socket, true)
|
93
|
+
EM.set_notify_readable(@signature, true)
|
94
|
+
EM.instance_variable_get('@conns')[@signature] = self
|
95
|
+
@connected = true
|
96
|
+
next_query
|
97
|
+
|
98
|
+
rescue Mysql::Error => e
|
99
|
+
EM.add_timer(1) { reconnect }
|
95
100
|
end
|
96
101
|
|
97
102
|
def execute(sql, cblk = nil, eblk = nil, retries = 0)
|
@@ -123,6 +128,8 @@ module EventMachine
|
|
123
128
|
end
|
124
129
|
|
125
130
|
def close
|
131
|
+
return unless @connected
|
132
|
+
|
126
133
|
detach
|
127
134
|
@mysql.close
|
128
135
|
@connected = false
|
data/spec/activerecord_spec.rb
CHANGED
@@ -48,4 +48,10 @@ describe "ActiveRecord Driver for EM-MySQLPlus" do
|
|
48
48
|
}
|
49
49
|
}
|
50
50
|
end
|
51
|
+
|
52
|
+
it "should fallback to blocking driver outside of EM loop" do
|
53
|
+
ActiveRecord::Base.establish_connection
|
54
|
+
r = Widget.find_by_sql("select sleep(0.01)")
|
55
|
+
r.size.should == 1
|
56
|
+
end
|
51
57
|
end
|
data/spec/database.yml
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ilya Grigorik
|
@@ -15,13 +15,14 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-03 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: eventmachine
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
@@ -65,6 +66,7 @@ rdoc_options:
|
|
65
66
|
require_paths:
|
66
67
|
- lib
|
67
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
68
70
|
requirements:
|
69
71
|
- - ">="
|
70
72
|
- !ruby/object:Gem::Version
|
@@ -72,6 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
74
|
- 0
|
73
75
|
version: "0"
|
74
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
75
78
|
requirements:
|
76
79
|
- - ">="
|
77
80
|
- !ruby/object:Gem::Version
|
@@ -81,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
84
|
requirements: []
|
82
85
|
|
83
86
|
rubyforge_project: em-mysqlplus
|
84
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.7
|
85
88
|
signing_key:
|
86
89
|
specification_version: 3
|
87
90
|
summary: Async MySQL driver for Ruby/Eventmachine
|