postqueue 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postqueue.rb +1 -0
- data/lib/postqueue/default_queue.rb +17 -0
- data/lib/postqueue/item/enqueue.rb +1 -1
- data/lib/postqueue/queue.rb +1 -1
- data/lib/postqueue/queue/callback.rb +2 -2
- data/lib/postqueue/queue/processing.rb +1 -1
- data/lib/postqueue/queue/select_and_lock.rb +1 -1
- data/lib/postqueue/version.rb +1 -1
- data/spec/postqueue/concurrency_spec.rb +1 -1
- data/spec/postqueue/default_queue_spec.rb +42 -0
- data/spec/postqueue/process_spec.rb +2 -2
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22dcc3ebd8cee3a0da1beec4578662009694403c
|
4
|
+
data.tar.gz: bcfc1044a1970d7055e4ecdde02c9b626d8cc3b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 923f4b85b6861c796cb36e33f1dd0687ce9f90ac9d76fe83dcb5911af380ea24b763e7e887e53adc8db4b1410e725ded983d6e012fc78c8ef8f1d252982989b3
|
7
|
+
data.tar.gz: a2343de315aa9be8387e88d13f12f7b65204fe8ecd3671c98241f31f8365fa04701f2c0a95f123e3d78ab7fba00758f72bcfb9c279e54aedcb4919653cb4291c
|
data/lib/postqueue.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module Postqueue
|
4
|
+
module DefaultQueue
|
5
|
+
def default_queue
|
6
|
+
@default_queue ||= new
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
extend DefaultQueue
|
11
|
+
|
12
|
+
extend SingleForwardable
|
13
|
+
|
14
|
+
def_delegators :default_queue, :enqueue
|
15
|
+
def_delegators :default_queue, :item_class, :batch_sizes, :on
|
16
|
+
def_delegators :default_queue, :process, :process_one
|
17
|
+
end
|
data/lib/postqueue/queue.rb
CHANGED
@@ -39,7 +39,7 @@ module Postqueue
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def idempotent_operation?(op)
|
42
|
-
idempotent_operations.fetch(op) { idempotent_operations.fetch(
|
42
|
+
idempotent_operations.fetch(op) { idempotent_operations.fetch("*", false) }
|
43
43
|
end
|
44
44
|
|
45
45
|
def idempotent_operation(op, flag = true)
|
@@ -29,11 +29,11 @@ module Postqueue
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def callback_for(op:)
|
32
|
-
callbacks[op] || callbacks[
|
32
|
+
callbacks[op] || callbacks["*"]
|
33
33
|
end
|
34
34
|
|
35
35
|
def on_missing_handler(op:, entity_ids:)
|
36
|
-
raise MissingHandler
|
36
|
+
raise MissingHandler, queue: self, op: op, entity_ids: entity_ids
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
@@ -25,7 +25,7 @@ module Postqueue
|
|
25
25
|
# passed in, that one is chosen as a filter condition, otherwise the op value
|
26
26
|
# of the first queue entry is used insteatd.
|
27
27
|
#
|
28
|
-
# This method will at maximum select and lock \a batch_size items.
|
28
|
+
# This method will at maximum select and lock \a batch_size items.
|
29
29
|
# If the \a batch_size configured in the queue is smaller than the value
|
30
30
|
# passed in here that one is used instead.
|
31
31
|
#
|
data/lib/postqueue/version.rb
CHANGED
@@ -20,7 +20,7 @@ describe "concurrency tests" do
|
|
20
20
|
ActiveRecord::Base.connection_pool.with_connection do |_conn|
|
21
21
|
log = File.open(LOG_FILE, "a")
|
22
22
|
queue = Postqueue.new
|
23
|
-
queue.on
|
23
|
+
queue.on "*" do |_op, entity_ids|
|
24
24
|
sleep(0.0001); log.write "#{entity_ids.first}\n"
|
25
25
|
end
|
26
26
|
queue.process_until_empty
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "default_queue" do
|
4
|
+
let(:queue) { Postqueue }
|
5
|
+
let(:items) { queue.item_class.all }
|
6
|
+
let(:item) { queue.item_class.first }
|
7
|
+
|
8
|
+
let(:processed_events) { @processed_events ||= [] }
|
9
|
+
|
10
|
+
before do
|
11
|
+
queue.batch_sizes["batchable"] = 10
|
12
|
+
queue.batch_sizes["other-batchable"] = 10
|
13
|
+
|
14
|
+
queue.on "*" do |op, entity_ids|
|
15
|
+
processed_events << [ op, entity_ids ]
|
16
|
+
end
|
17
|
+
|
18
|
+
queue.enqueue op: "batchable", entity_id: 12
|
19
|
+
queue.enqueue op: "batchable", entity_id: 13
|
20
|
+
queue.enqueue op: "other-batchable", entity_id: 14
|
21
|
+
queue.enqueue op: "batchable", entity_id: 15
|
22
|
+
queue.enqueue op: "other-batchable", entity_id: 16
|
23
|
+
end
|
24
|
+
|
25
|
+
it "processes one matching entry with batch_size 1" do
|
26
|
+
r = queue.process batch_size: 1
|
27
|
+
expect(r).to eq(1)
|
28
|
+
expect(items.map(&:entity_id)).to contain_exactly(13, 14, 15, 16)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "processes all matching entries" do
|
32
|
+
r = queue.process
|
33
|
+
expect(r).to eq(3)
|
34
|
+
expect(items.map(&:entity_id)).to contain_exactly(14, 16)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "honors search conditions" do
|
38
|
+
r = queue.process(op: "other-batchable")
|
39
|
+
expect(r).to eq(2)
|
40
|
+
expect(items.map(&:entity_id)).to contain_exactly(12, 13, 15)
|
41
|
+
end
|
42
|
+
end
|
@@ -10,7 +10,7 @@ describe "processing" do
|
|
10
10
|
queue.batch_sizes["batchable"] = 10
|
11
11
|
queue.batch_sizes["other-batchable"] = 10
|
12
12
|
|
13
|
-
queue.on
|
13
|
+
queue.on "*" do |op, entity_ids|
|
14
14
|
processed_events << [ op, entity_ids ]
|
15
15
|
end
|
16
16
|
end
|
@@ -44,7 +44,7 @@ describe "processing" do
|
|
44
44
|
queue.enqueue op: "otherop", entity_id: 112
|
45
45
|
called = false
|
46
46
|
queue.process_one(op: "otherop")
|
47
|
-
|
47
|
+
|
48
48
|
op, ids = processed_events.first
|
49
49
|
expect(op).to eq("otherop")
|
50
50
|
expect(ids).to eq([112])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postqueue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -145,6 +145,7 @@ extra_rdoc_files: []
|
|
145
145
|
files:
|
146
146
|
- README.md
|
147
147
|
- lib/postqueue.rb
|
148
|
+
- lib/postqueue/default_queue.rb
|
148
149
|
- lib/postqueue/item.rb
|
149
150
|
- lib/postqueue/item/enqueue.rb
|
150
151
|
- lib/postqueue/item/inserter.rb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/tracker/registry.rb
|
162
163
|
- lib/tracker/tracker.sql
|
163
164
|
- spec/postqueue/concurrency_spec.rb
|
165
|
+
- spec/postqueue/default_queue_spec.rb
|
164
166
|
- spec/postqueue/enqueue_spec.rb
|
165
167
|
- spec/postqueue/idempotent_ops_spec.rb
|
166
168
|
- spec/postqueue/postqueue_spec.rb
|