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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fd15294351f2f6e2be7d4c15d7ac509e097f3c5
4
- data.tar.gz: cbe1f9ca4e5bf7bbfa6027794e2c0ff26ad14c03
3
+ metadata.gz: 22dcc3ebd8cee3a0da1beec4578662009694403c
4
+ data.tar.gz: bcfc1044a1970d7055e4ecdde02c9b626d8cc3b6
5
5
  SHA512:
6
- metadata.gz: 5192d32ebb44a46f60df9303edb8cf2065edb42194e77e28576d2deba16dfbcc703c2c4f384f895a190cec68a327426936d1bfe48c157e8763e275a641945820
7
- data.tar.gz: c27d77120587844546d644d5bdfa38897a771080fd89654242b39c00ca95125c8916b5dbb751ff47ed8def82ba50cded1daf2090dc6424854c2bac5343f366f3
6
+ metadata.gz: 923f4b85b6861c796cb36e33f1dd0687ce9f90ac9d76fe83dcb5911af380ea24b763e7e887e53adc8db4b1410e725ded983d6e012fc78c8ef8f1d252982989b3
7
+ data.tar.gz: a2343de315aa9be8387e88d13f12f7b65204fe8ecd3671c98241f31f8365fa04701f2c0a95f123e3d78ab7fba00758f72bcfb9c279e54aedcb4919653cb4291c
data/lib/postqueue.rb CHANGED
@@ -2,6 +2,7 @@ require_relative "postqueue/logger"
2
2
  require_relative "postqueue/item"
3
3
  require_relative "postqueue/version"
4
4
  require_relative "postqueue/queue"
5
+ require_relative "postqueue/default_queue"
5
6
 
6
7
  module Postqueue
7
8
  def self.new(*args, &block)
@@ -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
@@ -15,7 +15,7 @@ module Postqueue
15
15
  end
16
16
 
17
17
  insert_item op: op, entity_id: entity_id
18
- return 1
18
+ 1
19
19
  end
20
20
 
21
21
  def self.enqueue_many(op:, entity_ids:, ignore_duplicates:) #:nodoc:
@@ -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('*', false) }
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.new(queue: self, op: op, entity_ids: entity_ids)
36
+ raise MissingHandler, queue: self, op: op, entity_ids: entity_ids
37
37
  end
38
38
 
39
39
  private
@@ -11,7 +11,7 @@ module Postqueue
11
11
  end
12
12
 
13
13
  # processes a single entry
14
- def process_one(op: nil, &block)
14
+ def process_one(op: nil)
15
15
  process(op: op, batch_size: 1)
16
16
  end
17
17
 
@@ -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
  #
@@ -1,3 +1,3 @@
1
1
  module Postqueue
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -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 '*' do |_op, entity_ids|
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 '*' do |op, entity_ids|
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.0
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