julien51-em-mysql 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/em-mysql.gemspec +2 -2
  2. data/lib/em/mysql.rb +10 -8
  3. metadata +5 -4
data/em-mysql.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
- s.name = 'em-mysql'
3
- s.version = '0.3.1'
2
+ s.name = 'julien51-em-mysql'
3
+ s.version = '0.3.2'
4
4
  s.date = '2009-06-23'
5
5
  s.summary = 'Async MySQL client API for Ruby/EventMachine'
6
6
  s.email = "em-mysql@tmm1.net"
data/lib/em/mysql.rb CHANGED
@@ -3,6 +3,8 @@ require 'eventmachine'
3
3
  require 'mysqlplus'
4
4
  require 'fcntl'
5
5
 
6
+ MAX_RETRIES_ON_DEADLOCKS = 10
7
+
6
8
  class Mysql
7
9
  def result
8
10
  @cur_result
@@ -36,7 +38,7 @@ class EventedMysql < EM::Connection
36
38
  log 'readable'
37
39
  if item = @current
38
40
  @current = nil
39
- start, response, sql, cblk, eblk = item
41
+ start, response, sql, cblk, eblk, retries = item
40
42
  log 'mysql response', Time.now-start, sql
41
43
  arg = case response
42
44
  when :raw
@@ -71,12 +73,12 @@ class EventedMysql < EM::Connection
71
73
  end
72
74
  rescue Mysql::Error => e
73
75
  log 'mysql error', e.message
74
- if e.message =~ /Deadlock/
75
- @@queue << [response, sql, cblk, eblk]
76
+ if e.message =~ /Deadlock/ and retries < MAX_RETRIES_ON_DEADLOCKS
77
+ @@queue << [response, sql, cblk, eblk, retries + 1]
76
78
  @processing = false
77
79
  next_query
78
80
  elsif DisconnectErrors.include? e.message
79
- @@queue << [response, sql, cblk, eblk]
81
+ @@queue << [response, sql, cblk, eblk, retries + 1]
80
82
  return close
81
83
  elsif cb = (eblk || @opts[:on_error])
82
84
  cb.call(e)
@@ -118,7 +120,7 @@ class EventedMysql < EM::Connection
118
120
  end
119
121
  end
120
122
 
121
- def execute sql, response = nil, cblk = nil, eblk = nil, &blk
123
+ def execute sql, response = nil, cblk = nil, eblk = nil, retries = 0, &blk
122
124
  cblk ||= blk
123
125
 
124
126
  begin
@@ -138,13 +140,13 @@ class EventedMysql < EM::Connection
138
140
  log 'mysql sending', sql
139
141
  @mysql.send_query(sql)
140
142
  else
141
- @@queue << [response, sql, cblk, eblk]
143
+ @@queue << [response, sql, cblk, eblk, retries]
142
144
  return
143
145
  end
144
146
  rescue Mysql::Error => e
145
147
  log 'mysql error', e.message
146
148
  if DisconnectErrors.include? e.message
147
- @@queue << [response, sql, cblk, eblk]
149
+ @@queue << [response, sql, cblk, eblk, retries]
148
150
  return close
149
151
  else
150
152
  raise e
@@ -152,7 +154,7 @@ class EventedMysql < EM::Connection
152
154
  end
153
155
 
154
156
  log 'queuing', response, sql
155
- @current = [Time.now, response, sql, cblk, eblk]
157
+ @current = [Time.now, response, sql, cblk, eblk, retries]
156
158
  end
157
159
 
158
160
  def close
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-em-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
@@ -36,9 +36,10 @@ files:
36
36
  - lib/em/mysql.rb
37
37
  - lib/sequel/async.rb
38
38
  - test.rb
39
- has_rdoc: false
39
+ has_rdoc: true
40
40
  homepage: http://github.com/tmm1/em-mysql
41
- licenses:
41
+ licenses: []
42
+
42
43
  post_install_message:
43
44
  rdoc_options: []
44
45
 
@@ -61,7 +62,7 @@ requirements: []
61
62
  rubyforge_project:
62
63
  rubygems_version: 1.3.5
63
64
  signing_key:
64
- specification_version: 2
65
+ specification_version: 3
65
66
  summary: Async MySQL client API for Ruby/EventMachine
66
67
  test_files: []
67
68