que 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a18d2e13eaf6870dbd5e912bf072b54d4f45e79d
4
- data.tar.gz: 74a6bef98e5c1911dcf944c05392941445f71da5
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjYzZDkwOTBkNmUxYjIxZjVkZGEzOTRiZjBmOWQ1OWZiNjUxOTRkYw==
5
+ data.tar.gz: !binary |-
6
+ MzIyOTk0ZTE1NGIzMTIwOGEzM2ZkZTAyMzM1NDE5ZDM0YjcwZTUxMQ==
5
7
  SHA512:
6
- metadata.gz: 22d13ee07b45cab14849d810ffa714d9f773b13a3509f9e5c20e10b1e192c760c4903eed5d8d1721614a29d85b4542d51c3aa440d491047b5cb540e0c497122b
7
- data.tar.gz: 8c8cab41047a14bf177e8394439213f4aef0e4688e53f9d99d765ce12d0bd5489db8bd36f335e2e76bf72a19fba4e0f6f3c22670650d3786ff8a6f939ba849dc
8
+ metadata.gz: !binary |-
9
+ OGVmMTc2MzNlYjkyNTQwYzhiNDZmMDJlOTdhMDViOGFhYzYzMzgzMGQ0MzY5
10
+ YzY1OTIzYjg5YmZjZDcyNjJkOWM2ZmY4MWFjNjQ0YmYzODQ4NmM5Y2I0Yjhi
11
+ Y2Q0YTkwYTk4NDlmNDM1Y2E5OWJlYWE1OWE2MDY5YzIxYTQ0ZWE=
12
+ data.tar.gz: !binary |-
13
+ NzlmZWZmY2RjZjc0OGJkNzJhODA5NWY5ZmZkYzY0M2VlMTk5M2NkODQyMmQ1
14
+ OWYzNjExYmMxMTdmYzQ5NGQ1NTBlNzY3NTA2MjQ5ZDQwZDM3M2FmMTY2ODUz
15
+ OTVjZjA0ZGVhM2VmZTFkMTViMmI2M2ZmYWM3M2U0N2Y4N2QyNmU=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.7.1 (2014-04-29)
2
+
3
+ * Fix errors with prepared statements when ActiveRecord reconnects to the database. (dvrensk)
4
+
5
+ * Don't use prepared statements when inside a transaction. This negates the risk of a prepared statement error harming the entire transaction. The query that benefits the most from preparation is the job-lock CTE, which is never run in a transaction, so the performance impact should be negligible.
6
+
1
7
  ### 0.7.0 (2014-04-09)
2
8
 
3
9
  * `JobClass.queue(*args)` has been deprecated and will be removed in version 1.0.0. Please use `JobClass.enqueue(*args)` instead.
@@ -58,14 +58,31 @@ module Que
58
58
 
59
59
  def execute_prepared(name, params)
60
60
  checkout do |conn|
61
+ # Prepared statement errors have the potential to foul up the entire
62
+ # transaction, so if we're in one, err on the side of safety.
63
+ return execute_sql(SQL[name], params) if in_transaction?
64
+
61
65
  statements = @prepared_statements[conn] ||= {}
62
66
 
63
- unless statements[name]
64
- conn.prepare("que_#{name}", SQL[name])
65
- statements[name] = true
66
- end
67
+ begin
68
+ unless statements[name]
69
+ conn.prepare("que_#{name}", SQL[name])
70
+ prepared_just_now = statements[name] = true
71
+ end
72
+
73
+ conn.exec_prepared("que_#{name}", params)
74
+ rescue ::PG::InvalidSqlStatementName => error
75
+ # Reconnections on ActiveRecord can cause the same connection
76
+ # objects to refer to new backends, so recover as well as we can.
67
77
 
68
- conn.exec_prepared("que_#{name}", params)
78
+ unless prepared_just_now
79
+ Que.log :level => 'warn', :event => "reprepare_statement", :name => name
80
+ statements[name] = false
81
+ retry
82
+ end
83
+
84
+ raise error
85
+ end
69
86
  end
70
87
  end
71
88
 
data/lib/que/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Que
2
- Version = '0.7.0'
2
+ Version = '0.7.1'
3
3
  end
@@ -31,6 +31,35 @@ unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
31
31
  end
32
32
  end
33
33
 
34
+ context "if the connection goes down and is reconnected" do
35
+ before do
36
+ Que::Job.enqueue
37
+ ActiveRecord::Base.connection.reconnect!
38
+ end
39
+
40
+ it "should recreate the prepared statements" do
41
+ expect { Que::Job.enqueue }.not_to raise_error
42
+ end
43
+
44
+ it "should work properly even in a transaction" do
45
+ ActiveRecord::Base.transaction do
46
+ expect { Que::Job.enqueue }.not_to raise_error
47
+ end
48
+
49
+ DB[:que_jobs].count.should == 2
50
+ end
51
+
52
+ it "should log this extraordinary event" do
53
+ $logger.messages.clear
54
+ Que::Job.enqueue
55
+ $logger.messages.count.should == 1
56
+ message = JSON.load($logger.messages.first)
57
+ message['lib'].should == 'que'
58
+ message['event'].should == 'reprepare_statement'
59
+ message['name'].should == 'insert_job'
60
+ end
61
+ end
62
+
34
63
  it "should instantiate args as ActiveSupport::HashWithIndifferentAccess" do
35
64
  ArgsJob.enqueue :param => 2
36
65
  Que::Job.work
data/spec/spec_helper.rb CHANGED
@@ -63,6 +63,11 @@ def $logger.method_missing(m, message)
63
63
  $logger_mutex.synchronize { messages << message }
64
64
  end
65
65
 
66
+ # Object includes Kernel#warn which is not what we expect, so remove:
67
+ def $logger.warn(message)
68
+ method_missing(:warn, message)
69
+ end
70
+
66
71
 
67
72
 
68
73
  # Helper to display spec descriptions.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: que
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,17 +112,17 @@ require_paths:
112
112
  - lib
113
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - '>='
120
+ - - ! '>='
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.0.3
125
+ rubygems_version: 2.2.2
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: A PostgreSQL-based Job Queue