queue_classic_plus 4.0.0.alpha14 → 4.0.0.alpha15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02d3b91c1e5eb2b3cd87c4431123bcdcd83546352a101a70d88663914cae8b75
4
- data.tar.gz: 2bae8d97dc7e05144fb5d398fafefb870aa0f476ea0d82cd595a26378ca16f75
3
+ metadata.gz: 634ceaedff254e0c5382a484d574d6971101362a88b9d2185303d95298de06c8
4
+ data.tar.gz: '03509124366e931f02d928226da3b05ec3e625c5888eaba88f5669ee090566b6'
5
5
  SHA512:
6
- metadata.gz: b536eafcf6c8a7fd0698a09a9f56b3bd944612df546c857f69784269472cba64a555c639cf856c6811bffdb0037b851d8fb73a3e661785ab295b8b2143408dd7
7
- data.tar.gz: f9cc374b667dfdb79f9adba615aab35bd49e2f90fda74eec04681d4f6288547235baba2b676abd118f51d227a436a6a571a8fd758f3828db15cf7436fff93073
6
+ metadata.gz: 4c8b6ff9e377c59b579c7309ee1f75e3fb583b00450ef09548f46d5d6e921c2553cf64037b259a1267b2781276f2e06ccceb3c8e5d6bc76373dc9e64e7a61522
7
+ data.tar.gz: d3852486ebdf22d4c59d142a8f00257f2fa7b0847d09704001644e56cb5ab91845ba154807bc2699491f379b62c98656da7b70735c9b3d3ba13638efaddfefb6
@@ -79,13 +79,19 @@ module QueueClassicPlus
79
79
  end
80
80
 
81
81
  def self.enqueue(method, *args)
82
- conn = QC.default_conn_adapter.connection
83
- conn.transaction do
84
- conn.exec("SELECT pg_advisory_xact_lock(#{queue_name_digest})")
85
- if can_enqueue?(method, *args)
86
- queue.enqueue(method, *serialized(args))
87
- end
88
- end
82
+ conn = QC.default_conn_adapter.connection
83
+ check_and_enqueue = proc do
84
+ conn.exec("SELECT pg_advisory_xact_lock(#{queue_name_digest})")
85
+ if can_enqueue?(method, *args)
86
+ queue.enqueue(method, *serialized(args))
87
+ end
88
+ end
89
+
90
+ if [PG::PQTRANS_ACTIVE, PG::PQTRANS_INTRANS].include?(conn.transaction_status)
91
+ check_and_enqueue.call
92
+ else
93
+ conn.transaction &check_and_enqueue
94
+ end
89
95
  end
90
96
 
91
97
  def self.enqueue_perform(*args)
@@ -1,3 +1,3 @@
1
1
  module QueueClassicPlus
2
- VERSION = '4.0.0.alpha14'.freeze
2
+ VERSION = '4.0.0.alpha15'.freeze
3
3
  end
data/spec/base_spec.rb CHANGED
@@ -44,6 +44,23 @@ describe QueueClassicPlus::Base do
44
44
  end
45
45
  end
46
46
 
47
+ context "when in a transaction" do
48
+ subject do
49
+ Class.new(QueueClassicPlus::Base) do
50
+ @queue = :test
51
+ lock!
52
+ end
53
+ end
54
+
55
+ it "does not create another transaction when enqueueing" do
56
+ conn = QC.default_conn_adapter.connection
57
+ expect(conn).to receive(:transaction).exactly(1).times.and_call_original
58
+ conn.transaction do
59
+ subject.do
60
+ end
61
+ end
62
+ end
63
+
47
64
  context "with default settings" do
48
65
  subject do
49
66
  Class.new(QueueClassicPlus::Base) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue_classic_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha14
4
+ version: 4.0.0.alpha15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-08 00:00:00.000000000 Z
13
+ date: 2023-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: queue_classic