queue_classic_plus 4.0.0.alpha14 → 4.0.0.alpha16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02d3b91c1e5eb2b3cd87c4431123bcdcd83546352a101a70d88663914cae8b75
4
- data.tar.gz: 2bae8d97dc7e05144fb5d398fafefb870aa0f476ea0d82cd595a26378ca16f75
3
+ metadata.gz: 1ca2467a415dbb231b97492a6b223945a08c79a704209c9f5cbdcc6317a51643
4
+ data.tar.gz: 497545d4065d6cd1c03a39591b04174fbff95899871a1b0dcb1d33a4d5cc4bdf
5
5
  SHA512:
6
- metadata.gz: b536eafcf6c8a7fd0698a09a9f56b3bd944612df546c857f69784269472cba64a555c639cf856c6811bffdb0037b851d8fb73a3e661785ab295b8b2143408dd7
7
- data.tar.gz: f9cc374b667dfdb79f9adba615aab35bd49e2f90fda74eec04681d4f6288547235baba2b676abd118f51d227a436a6a571a8fd758f3828db15cf7436fff93073
6
+ metadata.gz: 2c46e104255d291c0bee0e2c5517bb72c1ced81f860fb8f7ee1474973ed806f92c5352bfb060e9f538dcacd9e43dfd8ad2100539931bf21f9d567a4456e6e64c
7
+ data.tar.gz: 6102b297532d4cc30c30825deb42a82121460d773f0881a250ea5280803aa0d959279cf4e1baee8e4719d41840afbb1e332a9b598b9ef9711ceed1b31da31cbe
@@ -2,12 +2,16 @@ module QueueClassicPlus
2
2
  class Base
3
3
  extend QueueClassicPlus::InheritableAttribute
4
4
 
5
+ # Max value for bigint calculated from
6
+ # https://stackoverflow.com/questions/28960478/postgres-maximum-value-for-bigint
7
+ PG_BIGINT_MAX = 9223372036854775807.freeze
8
+
5
9
  def self.queue
6
10
  QC::Queue.new(@queue)
7
11
  end
8
12
 
9
13
  def self.queue_name_digest
10
- @queue_name_digest ||= @queue.to_s.to_i(36)
14
+ @queue_name_digest ||= @queue.to_s.to_i(36) % PG_BIGINT_MAX
11
15
  end
12
16
 
13
17
  inheritable_attr :locked
@@ -79,13 +83,19 @@ module QueueClassicPlus
79
83
  end
80
84
 
81
85
  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
86
+ conn = QC.default_conn_adapter.connection
87
+ check_and_enqueue = proc do
88
+ conn.exec("SELECT pg_advisory_xact_lock(#{queue_name_digest})")
89
+ if can_enqueue?(method, *args)
90
+ queue.enqueue(method, *serialized(args))
91
+ end
92
+ end
93
+
94
+ if [PG::PQTRANS_ACTIVE, PG::PQTRANS_INTRANS].include?(conn.transaction_status)
95
+ check_and_enqueue.call
96
+ else
97
+ conn.transaction &check_and_enqueue
98
+ end
89
99
  end
90
100
 
91
101
  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.alpha16'.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.alpha16
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-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: queue_classic