queue_classic_plus 4.0.0.alpha14 → 4.0.0.alpha16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/queue_classic_plus/base.rb +18 -8
- data/lib/queue_classic_plus/version.rb +1 -1
- data/spec/base_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ca2467a415dbb231b97492a6b223945a08c79a704209c9f5cbdcc6317a51643
|
4
|
+
data.tar.gz: 497545d4065d6cd1c03a39591b04174fbff95899871a1b0dcb1d33a4d5cc4bdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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)
|
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.
|
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-
|
13
|
+
date: 2023-08-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: queue_classic
|