perfectqueue 0.8.33 → 0.8.34

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/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ == 2014-05-20 version 0.8.34
2
+
3
+ * rdb_compat: use connection pooling. Users can specify as :use_connection_pooling
4
+ option. If connections use SSL, they are, by default, pooled. On the other hand,
5
+ if not, by default, connection pooling is not used.
6
+
1
7
  == 2014-04-23 version 0.8.33
2
8
 
3
9
  * Fixed nil variable exception at ChildProcessMonitor#try_join
@@ -48,16 +48,23 @@ module PerfectQueue
48
48
  user: uri.user,
49
49
  password: uri.password,
50
50
  host: uri.host,
51
- port: uri.port ? uri.port.to_i : 3306
51
+ port: uri.port ? uri.port.to_i : 3306,
52
+ max_connections: 1
52
53
  }
53
54
  options[:sslca] = config[:sslca] if config[:sslca]
54
55
 
55
56
  db_name = uri.path.split('/')[1]
56
57
  @db = Sequel.mysql2(db_name, options)
58
+ if config.fetch(:use_connection_pooling, nil) != nil
59
+ @use_connection_pooling = !!config[:use_connection_pooling]
60
+ else
61
+ @use_connection_pooling = !!config[:sslca]
62
+ end
57
63
  else
58
64
  raise ConfigError, "'sqlite' and 'mysql' are supported"
59
65
  end
60
66
 
67
+ @last_time = Time.now.to_i
61
68
  @mutex = Mutex.new
62
69
 
63
70
  connect {
@@ -110,7 +117,7 @@ SQL
110
117
 
111
118
  attr_reader :db
112
119
 
113
- #KEEPALIVE = 10
120
+ KEEPALIVE = 10
114
121
  MAX_RETRY = 10
115
122
  DEFAULT_DELETE_INTERVAL = 20
116
123
 
@@ -328,15 +335,15 @@ SQL
328
335
 
329
336
  protected
330
337
  def connect(&block)
331
- #now = Time.now.to_i
338
+ now = Time.now.to_i
332
339
  @mutex.synchronize do
333
- #if now - @last_time > KEEPALIVE
334
- # @db.disconnect
335
- #end
336
- #@last_time = now
340
+ # keepalive_timeout
341
+ @db.disconnect if now - @last_time > KEEPALIVE
342
+
337
343
  count = 0
338
344
  begin
339
345
  block.call
346
+ @last_time = now
340
347
  rescue
341
348
  # workaround for "Mysql2::Error: Deadlock found when trying to get lock; try restarting transaction" error
342
349
  if $!.to_s.include?('try restarting transaction')
@@ -350,9 +357,14 @@ SQL
350
357
  STDERR.puts err + "\n abort."
351
358
  end
352
359
  end
360
+
361
+ STDERR.puts "disconnects current connection: #{err}"
362
+ @db.disconnect
363
+
353
364
  raise
354
365
  ensure
355
- @db.disconnect
366
+ # connection_pooling
367
+ @db.disconnect if !@use_connection_pooling
356
368
  end
357
369
  end
358
370
  end
@@ -1,3 +1,3 @@
1
1
  module PerfectQueue
2
- VERSION = "0.8.33"
2
+ VERSION = "0.8.34"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfectqueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.33
4
+ version: 0.8.34
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-23 00:00:00.000000000 Z
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: -4181618303905023933
160
+ hash: -1427988048662614189
161
161
  required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  none: false
163
163
  requirements:
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  segments:
168
168
  - 0
169
- hash: -4181618303905023933
169
+ hash: -1427988048662614189
170
170
  requirements: []
171
171
  rubyforge_project:
172
172
  rubygems_version: 1.8.24