evt-consumer 0.5.0.4 → 0.6.0.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
  SHA1:
3
- metadata.gz: a06d0578ecaed78cc219810f3f5b53796592b7ff
4
- data.tar.gz: 327aa00f833ded2114f8abf3d263ebdf42bfe713
3
+ metadata.gz: 2475ecea2ff83320921192335e0a577a7be6c570
4
+ data.tar.gz: 431e4d264dbf0e5905e38ea0fe5122ca97507ed7
5
5
  SHA512:
6
- metadata.gz: 3f23e9ea6e60dea66642f82113562fc25d8bf6a2de1610e6dcff860b127fe0d9e8205120aee61cdf3267e6a4564c4a28681a380357a4c9e8928d3d3d6c609a55
7
- data.tar.gz: 849f63c2c49a652ed96c3d541f33744afe99919c042bd25f21f0de501bd9f6da9037419e76b35849002635a69b4eefa15bed691cc46493283bffcffa3ea9efb4
6
+ metadata.gz: fe951b092065c75f0a06965e6cfb5afda86fee1c9133a1d1791c6755560cd32a483eee26db43ea9bcb7b9b6547ffdca26259dff779e4855fcaf33384440db8ec
7
+ data.tar.gz: 36f378434b972906ee3abc8aaeba0aa2d0b32dab08409c5d78a314abc58ffd27a44793b20de11927a0a2a906174ae15abb9b7c6dc5d1c88204b08c8f35a2a859
@@ -19,23 +19,23 @@ module Consumer
19
19
  end
20
20
 
21
21
  handle Subscription::GetBatch::Reply do |get_batch_reply|
22
- events = get_batch_reply.batch
22
+ messages = get_batch_reply.batch
23
23
 
24
- logger.trace { "Received batch (Events: #{events.count})" }
24
+ logger.trace { "Received batch (Messages: #{messages.count})" }
25
25
 
26
26
  request_batch
27
27
 
28
- events.each do |message_data|
28
+ messages.each do |message_data|
29
29
  consumer.(message_data)
30
30
  end
31
31
 
32
- logger.debug { "Batch received (Events: #{events.count})" }
32
+ logger.debug { "Batch received (Events: #{messages.count})" }
33
33
  end
34
34
 
35
35
  def request_batch
36
36
  logger.trace { "Requesting batch" }
37
37
 
38
- get_batch = Subscription::GetBatch.new address
38
+ get_batch = Subscription::GetBatch.new(address)
39
39
 
40
40
  send.(get_batch, subscription_address)
41
41
 
@@ -8,6 +8,7 @@ module Consumer
8
8
  extend Start
9
9
 
10
10
  extend HandlerMacro
11
+ extend IdentifierMacro
11
12
 
12
13
  prepend Configure
13
14
 
@@ -29,16 +30,16 @@ module Consumer
29
30
  end
30
31
 
31
32
  def call(message_data)
32
- logger.trace { "Dispatching event (#{LogText.message_data message_data})" }
33
+ logger.trace { "Dispatching event (#{LogText.message_data(message_data)})" }
33
34
 
34
35
  dispatch.(message_data)
35
36
 
36
- update_position message_data.global_position
37
+ update_position(message_data.global_position)
37
38
 
38
- logger.info { "Event dispatched (#{LogText.message_data message_data})" }
39
+ logger.info { "Event dispatched (#{LogText.message_data(message_data)})" }
39
40
 
40
41
  rescue => error
41
- logger.error { "Error raised (Error Class: #{error.class}, Error Message: #{error.message}, #{LogText.message_data message_data})" }
42
+ logger.error { "Error raised (Error Class: #{error.class}, Error Message: #{error.message}, #{LogText.message_data(message_data)})" }
42
43
  error_raised error, message_data
43
44
  end
44
45
 
@@ -59,15 +60,19 @@ module Consumer
59
60
  Actor::Messaging::Send.(:stop, address)
60
61
  end
61
62
 
62
- threads.each &:join
63
+ threads.each(&:join)
63
64
 
64
65
  AsyncInvocation::Incorrect
65
66
  end
66
67
 
68
+ def identifier
69
+ self.class.identifier
70
+ end
71
+
67
72
  def start(&probe)
68
73
  _, subscription_thread = ::Actor::Start.(subscription)
69
74
 
70
- actor_address, actor_thread = Actor.start self, subscription, include: :thread
75
+ actor_address, actor_thread = Actor.start(self, subscription, include: :thread)
71
76
 
72
77
  if probe
73
78
  subscription_address = subscription.address
@@ -89,8 +94,10 @@ module Consumer
89
94
  def update_position(position)
90
95
  logger.trace { "Updating position (Position: #{position}, Interval: #{position_update_interval})" }
91
96
 
92
- if position % position_update_interval == 0
93
- position_store.put position
97
+ position_offset = position % position_update_interval
98
+
99
+ if position_offset == 0
100
+ position_store.put(position)
94
101
 
95
102
  logger.debug { "Updated position (Position: #{position}, Interval: #{position_update_interval})" }
96
103
  else
@@ -112,7 +119,7 @@ module Consumer
112
119
  def configure(batch_size: nil, session: nil, position_store: nil)
113
120
  logger.trace { "Configuring (Batch Size: #{batch_size}, Session: #{session.inspect})" }
114
121
 
115
- super if defined? super
122
+ super if defined?(super)
116
123
 
117
124
  starting_position = self.position_store.get
118
125
 
@@ -125,9 +132,9 @@ module Consumer
125
132
  cycle_timeout_milliseconds: cycle_timeout_milliseconds
126
133
  )
127
134
 
128
- handlers = self.class.handler_registry.get self
135
+ handlers = self.class.handler_registry.get(self)
129
136
 
130
- dispatch = Dispatch.configure self, handlers
137
+ dispatch = Dispatch.configure(self, handlers)
131
138
 
132
139
  logger.debug { "Done configuring (Batch Size: #{batch_size}, Session: #{session.inspect}, Starting Position: #{starting_position})" }
133
140
  end
@@ -139,7 +146,7 @@ module Consumer
139
146
  instance.position_update_interval = position_update_interval
140
147
  instance.cycle_maximum_milliseconds = cycle_maximum_milliseconds
141
148
  instance.cycle_timeout_milliseconds = cycle_timeout_milliseconds
142
- instance.configure batch_size: batch_size, position_store: position_store, session: session
149
+ instance.configure(batch_size: batch_size, position_store: position_store, session: session)
143
150
  instance
144
151
  end
145
152
  end
@@ -147,14 +154,14 @@ module Consumer
147
154
  module Run
148
155
  def run(stream_name, **arguments, &probe)
149
156
  instance = build stream_name, **arguments
150
- instance.run &probe
157
+ instance.run(&probe)
151
158
  end
152
159
  end
153
160
 
154
161
  module Start
155
162
  def start(stream_name, **arguments, &probe)
156
163
  instance = build stream_name, **arguments
157
- instance.start &probe
164
+ instance.start(&probe)
158
165
  end
159
166
  end
160
167
 
@@ -162,7 +169,7 @@ module Consumer
162
169
  def handler_macro(handler=nil, &block)
163
170
  handler ||= block
164
171
 
165
- handler_registry.register handler
172
+ handler_registry.register(handler)
166
173
  end
167
174
  alias_method :handler, :handler_macro
168
175
 
@@ -170,4 +177,20 @@ module Consumer
170
177
  @handler_registry ||= HandlerRegistry.new
171
178
  end
172
179
  end
180
+
181
+ module IdentifierMacro
182
+ attr_writer :identifier
183
+
184
+ def identifier_macro(identifier)
185
+ self.identifier = identifier
186
+ end
187
+
188
+ def identifier(identifier=nil)
189
+ if identifier.nil?
190
+ @identifier
191
+ else
192
+ identifier_macro(identifier)
193
+ end
194
+ end
195
+ end
173
196
  end
@@ -9,6 +9,7 @@ require 'consumer/controls/get'
9
9
  require 'consumer/controls/get/incrementing'
10
10
  require 'consumer/controls/handle'
11
11
  require 'consumer/controls/id'
12
+ require 'consumer/controls/identifier'
12
13
  require 'consumer/controls/position'
13
14
  require 'consumer/controls/stream_name'
14
15
 
@@ -2,7 +2,7 @@ module Consumer
2
2
  module Controls
3
3
  module Consumer
4
4
  def self.example
5
- Example.new StreamName.example
5
+ Example.new(StreamName.example)
6
6
  end
7
7
 
8
8
  class Example
@@ -11,8 +11,8 @@ module Consumer
11
11
  handler Handle::Example
12
12
 
13
13
  def configure(session: nil, batch_size: nil, position_store: nil)
14
- Get::Example.configure self
15
- PositionStore::Example.configure self, position_store: position_store
14
+ Get::Example.configure(self)
15
+ PositionStore::Example.configure(self, position_store: position_store)
16
16
  end
17
17
  end
18
18
  end
@@ -3,10 +3,7 @@ module Consumer
3
3
  module Consumer
4
4
  class Incrementing
5
5
  include ::Consumer
6
-
7
- def self.logger
8
- @logger ||= ::Log.get self
9
- end
6
+ include ::Log::Dependency
10
7
 
11
8
  handler do |message_data|
12
9
  logger.info { "Handled event (StreamName: #{message_data.stream_name}, GlobalPosition: #{message_data.global_position})" }
@@ -20,9 +17,9 @@ module Consumer
20
17
  sleep_duration = ENV['SLEEP_DURATION'] || 100
21
18
  sleep_duration = sleep_duration.to_i
22
19
 
23
- Get::Incrementing.configure self, sleep_duration
20
+ Get::Incrementing.configure(self, sleep_duration)
24
21
 
25
- PositionStore::LocalFile.configure self, position_store: position_store
22
+ PositionStore::LocalFile.configure(self, position_store: position_store)
26
23
  end
27
24
  end
28
25
  end
@@ -5,7 +5,7 @@ module Consumer
5
5
  Example.new
6
6
  end
7
7
 
8
- Example = Class.new StandardError
8
+ Example = Class.new(RuntimeError)
9
9
  end
10
10
  end
11
11
  end
@@ -15,7 +15,7 @@ module Consumer
15
15
  def call(stream_name, position: nil)
16
16
  position ||= 0
17
17
 
18
- stream = streams.fetch stream_name do
18
+ stream = streams.fetch(stream_name) do
19
19
  return nil
20
20
  end
21
21
 
@@ -7,7 +7,7 @@ module Consumer
7
7
  initializer :sleep_duration
8
8
 
9
9
  def self.build(sleep_duration)
10
- new sleep_duration
10
+ new(sleep_duration)
11
11
  end
12
12
 
13
13
  def call(stream_name, position: nil)
@@ -27,7 +27,10 @@ module Consumer
27
27
 
28
28
  class MessageData
29
29
  def self.get(stream_name, global_position, position)
30
- data = { :position => position, :global_position => global_position }
30
+ data = {
31
+ :position => position,
32
+ :global_position => global_position
33
+ }
31
34
 
32
35
  Controls::MessageData.example(
33
36
  stream_name: stream_name,
@@ -9,15 +9,15 @@ module Consumer
9
9
  include Messaging::Handle
10
10
 
11
11
  def handle(message_data)
12
- handled_events << message_data
12
+ handled_messages << message_data
13
13
  end
14
14
 
15
- def handled_events
16
- @handled_events ||= []
15
+ def handled_messages
16
+ @handled_messages ||= []
17
17
  end
18
18
 
19
19
  def handled?(message_data)
20
- handled_events.include? message_data
20
+ handled_messages.include?(message_data)
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,9 @@
1
+ module Consumer
2
+ module Controls
3
+ module Identifier
4
+ def self.example
5
+ 'some-consumer'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -10,10 +10,16 @@ module Consumer
10
10
 
11
11
  attr_accessor :telemetry_sink
12
12
 
13
+ def self.build
14
+ instance = new
15
+ instance.configure
16
+ instance
17
+ end
18
+
13
19
  def configure
14
20
  self.telemetry_sink = ::Consumer::PositionStore::Telemetry::Sink.new
15
21
 
16
- telemetry.register telemetry_sink
22
+ telemetry.register(telemetry_sink)
17
23
  end
18
24
 
19
25
  def get
@@ -4,14 +4,20 @@ module Consumer
4
4
  class LocalFile
5
5
  include Consumer::PositionStore
6
6
 
7
+ def self.build
8
+ instance = new
9
+ instance.configure
10
+ instance
11
+ end
12
+
7
13
  def get
8
- return 0 unless File.exist? path
9
- text = File.read path
14
+ return 0 unless File.exist?(path)
15
+ text = File.read(path)
10
16
  text.to_i
11
17
  end
12
18
 
13
19
  def put(position)
14
- File.write path, position
20
+ File.write(path, position)
15
21
  end
16
22
 
17
23
  def path
@@ -7,10 +7,10 @@ module Consumer
7
7
  get = Get.example
8
8
 
9
9
  unless batch.nil?
10
- get.set_batch stream_name, batch, position
10
+ get.set_batch(stream_name, batch, position)
11
11
  end
12
12
 
13
- subscription = ::Consumer::Subscription.new stream_name, get
13
+ subscription = ::Consumer::Subscription.new(stream_name, get)
14
14
 
15
15
  subscription.position = position if position
16
16
 
@@ -10,20 +10,20 @@ module Consumer
10
10
  instance = new
11
11
 
12
12
  handlers.each do |handler|
13
- instance.add_handler handler
13
+ instance.add_handler(handler)
14
14
  end
15
15
 
16
16
  instance
17
17
  end
18
18
 
19
19
  def call(message_data)
20
- logger.trace { "Dispatching event (#{LogText.message_data message_data})" }
20
+ logger.trace { "Dispatching event (#{LogText.message_data(message_data)})" }
21
21
 
22
22
  handlers.each do |handle|
23
23
  handle.(message_data)
24
24
  end
25
25
 
26
- logger.debug { "Event dispatched (#{LogText.message_data message_data}, Handlers Count: #{handlers.count})" }
26
+ logger.debug { "Event dispatched (#{LogText.message_data(message_data)}, Handlers Count: #{handlers.count})" }
27
27
 
28
28
  nil
29
29
  end
@@ -37,12 +37,12 @@ module Consumer
37
37
  end
38
38
 
39
39
  def to_proc
40
- method :call
40
+ method(:call)
41
41
  end
42
42
 
43
43
  module Assertions
44
44
  def handler?(handle)
45
- handler_registry.registered? handle
45
+ handler_registry.registered?(handle)
46
46
  end
47
47
  end
48
48
  end
@@ -7,25 +7,25 @@ module Consumer
7
7
 
8
8
  class Dispatch
9
9
  def call(message_data)
10
- dispatched_events << message_data
10
+ dispatched_messages << message_data
11
11
  end
12
12
 
13
13
  def add_handler(handle)
14
14
  handlers << handle
15
15
  end
16
16
 
17
- def dispatched_events
18
- @dispatched_events ||= []
17
+ def dispatched_messages
18
+ @dispatched_messages ||= []
19
19
  end
20
20
 
21
21
  def dispatched?(message_data=nil, &block)
22
22
  if message_data.nil?
23
23
  block ||= proc { true }
24
24
  else
25
- block ||= proc { |e| message_data == e }
25
+ block ||= proc { |msg| message_data == msg }
26
26
  end
27
27
 
28
- dispatched_events.any? &block
28
+ dispatched_messages.any? &block
29
29
  end
30
30
 
31
31
  def handlers
@@ -33,7 +33,7 @@ module Consumer
33
33
  end
34
34
 
35
35
  def handler?(handler)
36
- handlers.include? handler
36
+ handlers.include?(handler)
37
37
  end
38
38
  end
39
39
  end
@@ -5,17 +5,17 @@ module Consumer
5
5
  configure :handler_registry
6
6
 
7
7
  def register(handler)
8
- logger.trace { "Registering handler (Handler: #{LogText.handler handler})" }
8
+ logger.trace { "Registering handler (Handler: #{LogText.handler(handler)})" }
9
9
 
10
10
  if registered? handler
11
- error_message = "Handler is already registered (Handler: #{LogText.handler handler})"
12
- logger.error error_message
11
+ error_message = "Handler is already registered (Handler: #{LogText.handler(handler)})"
12
+ logger.error { error_message }
13
13
  raise Error, error_message
14
14
  end
15
15
 
16
16
  entries << handler
17
17
 
18
- logger.debug { "Handler registered (Handler: #{LogText.handler handler})" }
18
+ logger.debug { "Handler registered (Handler: #{LogText.handler(handler)})" }
19
19
 
20
20
  handler
21
21
  end
@@ -24,7 +24,7 @@ module Consumer
24
24
  entries.map do |handler|
25
25
  if handler.is_a? Proc
26
26
  proc { |message_data|
27
- consumer.instance_exec message_data, &handler
27
+ consumer.instance_exec(message_data, &handler)
28
28
  }
29
29
  else
30
30
  handler.build
@@ -36,7 +36,7 @@ module Consumer
36
36
  entries.any? do |entry|
37
37
  return true if handler == entry
38
38
 
39
- next if entry.is_a? Proc
39
+ next if entry.is_a?(Proc)
40
40
 
41
41
  handler === entry
42
42
  end
@@ -60,6 +60,6 @@ module Consumer
60
60
  end
61
61
  end
62
62
 
63
- Error = Class.new StandardError
63
+ Error = Class.new(RuntimeError)
64
64
  end
65
65
  end
@@ -15,13 +15,11 @@ module Consumer
15
15
  end
16
16
  end
17
17
 
18
- Virtual::Method.define self, :configure
18
+ Virtual::Method.define(self, :configure)
19
19
 
20
20
  module Build
21
- def build
22
- instance = new
23
- instance.configure
24
- instance
21
+ def self.extended(cls)
22
+ Virtual::PureMethod.define(cls.singleton_class, :build)
25
23
  end
26
24
  end
27
25
 
@@ -31,13 +29,13 @@ module Consumer
31
29
 
32
30
  if position_store.nil?
33
31
  if arguments.any?
34
- position_store = build *arguments, **keyword_arguments
32
+ position_store = build(*arguments, **keyword_arguments)
35
33
  else
36
- position_store = build *arguments
34
+ position_store = build(*arguments)
37
35
  end
38
36
  end
39
37
 
40
- receiver.public_send "#{attr_name}=", position_store
38
+ receiver.public_send("#{attr_name}=", position_store)
41
39
 
42
40
  position_store
43
41
  end
@@ -45,7 +43,7 @@ module Consumer
45
43
 
46
44
  module Configure
47
45
  def configure
48
- ::Telemetry.configure self
46
+ ::Telemetry.configure(self)
49
47
 
50
48
  super
51
49
  end
@@ -53,7 +51,7 @@ module Consumer
53
51
 
54
52
  module Get
55
53
  def self.prepended(cls)
56
- Virtual::PureMethod.define cls, :get
54
+ Virtual::PureMethod.define(cls, :get)
57
55
  end
58
56
 
59
57
  def get
@@ -63,7 +61,7 @@ module Consumer
63
61
 
64
62
  logger.info { "Get position done (Position: #{position || '(none)'})" }
65
63
 
66
- telemetry.record :get, Telemetry::Get.new(position)
64
+ telemetry.record(:get, Telemetry::Get.new(position))
67
65
 
68
66
  position
69
67
  end
@@ -71,7 +69,7 @@ module Consumer
71
69
 
72
70
  module Put
73
71
  def self.prepended(cls)
74
- Virtual::Method.define cls, :put
72
+ Virtual::Method.define(cls, :put)
75
73
  end
76
74
 
77
75
  def put(position)
@@ -81,7 +79,7 @@ module Consumer
81
79
 
82
80
  logger.info { "Put position done (Position: #{position})" }
83
81
 
84
- telemetry.record :put, Telemetry::Put.new(position)
82
+ telemetry.record(:put, Telemetry::Put.new(position))
85
83
 
86
84
  nil
87
85
  end
@@ -8,8 +8,8 @@ module Consumer
8
8
  record :put
9
9
  end
10
10
 
11
- Get = Struct.new :position
12
- Put = Struct.new :position
11
+ Get = Struct.new(:position)
12
+ Put = Struct.new(:position)
13
13
  end
14
14
  end
15
15
  end
@@ -20,7 +20,7 @@ module Consumer
20
20
  cycle_maximum_milliseconds ||= Defaults.cycle_maximum_milliseconds
21
21
  cycle_timeout_milliseconds ||= Defaults.cycle_timeout_milliseconds
22
22
 
23
- instance = new stream_name, get
23
+ instance = new(stream_name, get)
24
24
 
25
25
  instance.position = position
26
26
 
@@ -67,7 +67,7 @@ module Consumer
67
67
 
68
68
  batch = reset_next_batch
69
69
 
70
- reply_message = get_batch.reply_message batch
70
+ reply_message = get_batch.reply_message(batch)
71
71
 
72
72
  send.(reply_message, get_batch.reply_address)
73
73
 
@@ -1,6 +1,6 @@
1
1
  module Consumer
2
2
  class Subscription
3
- GetBatch = Struct.new :reply_address
3
+ GetBatch = Struct.new(:reply_address)
4
4
 
5
5
  class GetBatch
6
6
  include ::Actor::Messaging::Message
@@ -6,21 +6,21 @@ module Consumer
6
6
 
7
7
  class Consumer
8
8
  def call(message_data)
9
- consumed_events << message_data
9
+ dispatched_messages << message_data
10
10
  end
11
11
 
12
- def consumed_events
13
- @consumed_events ||= []
12
+ def dispatched_messages
13
+ @dispatched_messages ||= []
14
14
  end
15
15
 
16
- def consumed?(message_data=nil, &block)
16
+ def dispatched?(message_data=nil, &block)
17
17
  if message_data.nil?
18
18
  block ||= proc { true }
19
19
  else
20
- block ||= proc { |e| message_data == e }
20
+ block ||= proc { |msg| message_data == msg }
21
21
  end
22
22
 
23
- consumed_events.any? &block
23
+ dispatched_messages.any?(&block)
24
24
  end
25
25
  end
26
26
  end
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.5.0.4
4
+ version: 0.6.0.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: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ntl-actor
@@ -99,6 +99,7 @@ files:
99
99
  - lib/consumer/controls/get/incrementing.rb
100
100
  - lib/consumer/controls/handle.rb
101
101
  - lib/consumer/controls/id.rb
102
+ - lib/consumer/controls/identifier.rb
102
103
  - lib/consumer/controls/message_data.rb
103
104
  - lib/consumer/controls/message_data/batch.rb
104
105
  - lib/consumer/controls/position.rb