em-mysqlplus 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -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.4"
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-07-06}
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.6}
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::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
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
- @connection = EventMachine::MySQL.new({
19
- :host => @hostname,
20
- :port => @port,
21
- :database => @config[:database],
22
- :password => @config[:password],
23
- :socket => @config[:socket]
24
- })
25
-
26
- configure_connection
27
- @connection
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
- ConnectionAdapters::EmMysqlAdapter.new(nil, logger, [host, port], [database, username, password], config)
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
@@ -22,7 +22,7 @@ module ActiveRecord
22
22
  fiber.resume(false)
23
23
  end
24
24
  @queue << fiber
25
- returning Fiber.yield do
25
+ Fiber.yield.tap do
26
26
  x.cancel
27
27
  end
28
28
  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
- EM.add_timer(0) do
85
- @processing = false
86
- @mysql = @conn.connect_socket(@opts)
87
- @fd = @mysql.socket
87
+ def reconnect
88
+ @processing = false
89
+ @mysql = @conn.connect_socket(@opts)
90
+ @fd = @mysql.socket
88
91
 
89
- @signature = EM.attach_fd(@mysql.socket, true)
90
- EM.set_notify_readable @signature, true
91
- EM.instance_variable_get('@conns')[@signature] = self
92
- @connected = true
93
- next_query
94
- end
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  test:
2
2
  adapter: em_mysqlplus
3
3
  database: widgets
4
- user: root
4
+ username: root
5
5
  pool: 3
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
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-07-06 00:00:00 -04:00
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.6
87
+ rubygems_version: 1.3.7
85
88
  signing_key:
86
89
  specification_version: 3
87
90
  summary: Async MySQL driver for Ruby/Eventmachine