evt-consumer 0.11.0.3 → 0.11.1.0

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: e969a682c0e9a3266862786dedd42c714e5bd49e662444b92a09e44abaf88dc6
4
- data.tar.gz: 46bc457ada751040b08b9d8386f7a1b73dc2619e7c45df45e862d8025f37d295
3
+ metadata.gz: d59370128eb98868d476174baba504dbfcd3bd07f2fe0aa1cf262cf88d63f99e
4
+ data.tar.gz: a89e817d675aca9cf8d635c5cf73c184dc67bffa6fe0431606d9bfa67acea9e7
5
5
  SHA512:
6
- metadata.gz: 65d7b9f143d8e42dc42875d6f2d1e0f5b7aa55b058aea5b47f58e82abb0f91e6c8c48fa0cca1fddf5018d349c05c22d2072464e049040ae0de8e11a2dc5c78b4
7
- data.tar.gz: 364a0ac290d971286ad46298fc2d867ee40ca2eadf33145f8649f082c9232123070c71d57030360478ee1e8aff5e09b95940ce68581bba971708e4ba6f9c6bdb
6
+ metadata.gz: 572476d4ba197f55312e1b42f64785aa12e54aa6a0b009569a6892ca45ecfdaaf4506691ebb39f49a24212633478a0a0ca42f06cf9ac3654a6e738b7800fe086
7
+ data.tar.gz: 46fd4742ec78e986bf6c99f8411a78506963c8c173eaec5c7057f49631904bb7d176549293bec7fc231962a33447e8328ee9af70d212f76ab6bfa4e581d4ca2d
@@ -5,12 +5,21 @@ module Consumer
5
5
  include Initializer
6
6
  include Log::Dependency
7
7
 
8
- initializer :subscription_address
8
+ initializer :subscription_address, a(:delay_threshold)
9
9
 
10
10
  dependency :consumer, Consumer
11
11
 
12
+ attr_writer :prefetch_queue
13
+ def prefetch_queue
14
+ @prefetch_queue ||= []
15
+ end
16
+
12
17
  def self.build(consumer, subscription)
13
- instance = new subscription.address
18
+ subscription_address = subscription.address
19
+
20
+ delay_threshold = subscription.batch_size
21
+
22
+ instance = new(subscription_address, delay_threshold)
14
23
  instance.consumer = consumer
15
24
  instance.configure
16
25
  instance
@@ -21,27 +30,57 @@ module Consumer
21
30
  end
22
31
 
23
32
  handle Subscription::GetBatch::Reply do |get_batch_reply|
24
- messages = get_batch_reply.batch
33
+ received_batch = get_batch_reply.batch
25
34
 
26
- logger.trace { "Received batch (Messages: #{messages.count})" }
35
+ logger.trace(tag: :actor) { "Received batch (Received Batch Size: #{received_batch.size}, Prefetch Queue Depth: #{prefetch_queue.size}, Delay Threshold: #{delay_threshold})" }
27
36
 
28
- request_batch
37
+ prefetch_queue_empty = prefetch_queue.empty?
38
+
39
+ self.prefetch_queue += received_batch
40
+
41
+ unless prefetch_queue.size > delay_threshold
42
+ request_batch
43
+ end
44
+
45
+ if prefetch_queue_empty
46
+ next_message = :dispatch
47
+ end
29
48
 
30
- messages.each do |message_data|
31
- consumer.dispatch(message_data)
49
+ logger.debug(tag: :actor) { "Batch received (Received Batch Size: #{received_batch.size}, Prefetch Queue Depth: #{prefetch_queue.size}, Delay Threshold: #{delay_threshold}, Next Actor Message: #{next_message || '(none)'})" }
50
+
51
+ next_message
52
+ end
53
+
54
+ handle :dispatch do
55
+ logger.trace(tag: :actor) { "Dispatching Message (Prefetch Queue Depth: #{prefetch_queue.size}, Delay Threshold: #{delay_threshold})" }
56
+
57
+ dispatch_message = prefetch_queue.shift
58
+
59
+ if prefetch_queue.size == delay_threshold
60
+ request_batch
32
61
  end
33
62
 
34
- logger.debug { "Batch received (Events: #{messages.count})" }
63
+ consumer.dispatch(dispatch_message)
64
+
65
+ unless prefetch_queue.empty?
66
+ next_message = :dispatch
67
+ end
68
+
69
+ logger.debug(tag: :actor) { "Dispatched Message (Prefetch Queue Depth: #{prefetch_queue.size}, Delay Threshold: #{delay_threshold}, Global Position: #{dispatch_message.global_position}, Next Actor Message: #{next_message || '(none)'})" }
70
+
71
+ next_message
35
72
  end
36
73
 
37
74
  def request_batch
38
- logger.trace { "Requesting batch" }
75
+ logger.trace(tag: :actor) { "Requesting batch (Prefetch Queue Depth: #{prefetch_queue.size}, Delay Threshold: #{delay_threshold})" }
39
76
 
40
77
  get_batch = Subscription::GetBatch.new(address)
41
78
 
42
79
  send.(get_batch, subscription_address)
43
80
 
44
- logger.debug { "Send batch request" }
81
+ logger.debug(tag: :actor) { "Sent batch request (Prefetch Queue Depth: #{prefetch_queue.size}, Delay Threshold: #{delay_threshold})" }
82
+
83
+ nil
45
84
  end
46
85
  end
47
86
  end
@@ -20,6 +20,8 @@ require 'consumer/controls/subscription'
20
20
  require 'consumer/controls/handle'
21
21
  require 'consumer/controls/handle/raise_error'
22
22
 
23
+ require 'consumer/controls/actor'
24
+
23
25
  require 'consumer/controls/consumer'
24
26
  require 'consumer/controls/consumer/incrementing'
25
27
  require 'consumer/controls/consumer/error_handler'
@@ -0,0 +1,24 @@
1
+ module Consumer
2
+ module Controls
3
+ module Actor
4
+ def self.example(subscription_address: nil, delay_threshold: nil)
5
+ delay_threshold ||= DelayThreshold.example
6
+ subscription_address ||= Address.example
7
+
8
+ ::Consumer::Actor.new(subscription_address, delay_threshold)
9
+ end
10
+
11
+ module DelayThreshold
12
+ def self.example
13
+ Get.default_batch_size
14
+ end
15
+ end
16
+
17
+ module Address
18
+ def self.example
19
+ ::Actor::Messaging::Address.build
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,17 +1,27 @@
1
1
  module Consumer
2
2
  module Controls
3
3
  module Get
4
- def self.example
5
- Example.new
4
+ def self.example(batch_size: nil)
5
+ Example.build(batch_size: batch_size)
6
+ end
7
+
8
+ def self.default_batch_size
9
+ MessageData::Batch.size
6
10
  end
7
11
 
8
12
  class Example
9
- extend ::Configure::Macro
13
+ include ::Configure
14
+
15
+ include MessageStore::Get
16
+
17
+ initializer :batch_size
10
18
 
11
19
  configure :get
12
20
 
13
- def self.build
14
- new
21
+ def self.build(batch_size: nil)
22
+ batch_size ||= Get.default_batch_size
23
+
24
+ new(batch_size)
15
25
  end
16
26
 
17
27
  def call(stream_name, position: nil)
@@ -6,8 +6,8 @@ module Consumer
6
6
  end
7
7
 
8
8
  class Example
9
- extend ::Configure::Macro
10
- extend ::Settings::Setting::Macro
9
+ include ::Configure
10
+ include Settings::Setting
11
11
 
12
12
  configure :session
13
13
 
@@ -1,10 +1,10 @@
1
1
  module Consumer
2
2
  module Controls
3
3
  module Subscription
4
- def self.example(next_batch: nil, batch: nil, position: nil)
4
+ def self.example(next_batch: nil, batch: nil, position: nil, batch_size: nil)
5
5
  stream_name = StreamName.example
6
6
 
7
- get = Get.example
7
+ get = Get.example(batch_size: batch_size)
8
8
 
9
9
  unless batch.nil?
10
10
  get.set_batch(stream_name, batch, position)
@@ -17,6 +17,10 @@ module Consumer
17
17
  @position ||= 0
18
18
  end
19
19
 
20
+ def batch_size
21
+ get.batch_size
22
+ end
23
+
20
24
  dependency :poll, Poll
21
25
 
22
26
  def self.build(stream_name, get, position: nil, poll_interval_milliseconds: nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0.3
4
+ version: 0.11.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2018-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ntl-actor
@@ -104,6 +104,7 @@ files:
104
104
  - lib/consumer/actor.rb
105
105
  - lib/consumer/consumer.rb
106
106
  - lib/consumer/controls.rb
107
+ - lib/consumer/controls/actor.rb
107
108
  - lib/consumer/controls/category.rb
108
109
  - lib/consumer/controls/consumer.rb
109
110
  - lib/consumer/controls/consumer/error_handler.rb