evt-consumer 2.2.0.0 → 2.3.1.0

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
  SHA256:
3
- metadata.gz: d005131cba1d68a95028facee2e86fb2936e29ae0fe296a746f4e0e25abfc910
4
- data.tar.gz: caf16c231eb6195749b4b2190843ab87aed7735f4fd3b3da72555bab45f8ea76
3
+ metadata.gz: cf9c47da47df09523d2007d47a2bd92aa8463924f327261c0e5a1215efb16a81
4
+ data.tar.gz: 3ce5caed62500286a552af1940b6892e45c2c60ac235acb11bea52ab0ccbd79e
5
5
  SHA512:
6
- metadata.gz: 332338327a4a4fc99a3010e1e62b0dd840d64914efba85d3f90a22a001df3215c43f49933b213ac6ae7bef78dfe2018b3cb6dcf051c40b42eb278e5d547dd0a8
7
- data.tar.gz: 76e5105a629fbd97447d2423139b08ecf1d33a1cdb513bc662cacf3e4ec969888ee2b3da677fdc009583490f313d9067effac3e1c9087ee074ff9760d2bca24a
6
+ metadata.gz: f3e8b9b68405943aec82c4d2ebc5d6de35419fd8715bee00fab9476e833ec2521e18f3f208c14f3d81dd4038faf255c66b21a1ed8f7f717dd9b0e5c0bc2cdd2d
7
+ data.tar.gz: cde3e28a744e3eefde6367eb7f4425d2faacff56b7b65ccd237d0144079a5b8de1c4b554a7e763e091a38dacb1f0e2c554735add6fa602b135ecefa76f793a90
@@ -33,9 +33,11 @@ module Consumer
33
33
  @position_update_counter ||= 0
34
34
  end
35
35
 
36
+ attr_accessor :poll_interval_milliseconds
37
+
36
38
  attr_accessor :session
37
39
 
38
- attr_accessor :poll_interval_milliseconds
40
+ attr_accessor :supplemental_settings
39
41
 
40
42
  dependency :get, MessageStore::Get
41
43
  dependency :position_store, PositionStore
@@ -49,34 +51,20 @@ module Consumer
49
51
  end
50
52
  end
51
53
 
52
- def dispatch(message_data)
53
- logger.trace { "Dispatching message (#{LogText.message_data(message_data)})" }
54
+ def start(&probe)
55
+ logger.info(tags: [:consumer, :start]) { "Starting consumer: #{self.class.name} (Category: #{category}, Identifier: #{identifier || '(none)'}, Position: #{subscription.position})" }
54
56
 
55
- self.class.handler_registry.each do |handler|
56
- handler.(message_data, session: session)
57
+ if Defaults.startup_info?
58
+ print_info
57
59
  end
58
60
 
59
- update_position(message_data.global_position)
60
-
61
- logger.info { "Message dispatched (#{LogText.message_data(message_data)})" }
62
- rescue => error
63
- logger.error { "Error raised (Error Class: #{error.class}, Error Message: #{error.message}, #{LogText.message_data(message_data)})" }
64
- error_raised(error, message_data)
65
- end
66
-
67
- def start(&probe)
68
- logger.info(tag: :*) { "Starting consumer: #{self.class.name} (Category: #{category}, Identifier: #{identifier || '(none)'}, Position: #{subscription.position})" }
61
+ log_info
62
+ starting if respond_to?(:starting)
69
63
 
70
64
  if not MessageStore::StreamName.category?(category)
71
65
  raise Error, "Consumer's stream name must be a category (Stream Name: #{category})"
72
66
  end
73
67
 
74
- starting() if respond_to?(:starting)
75
-
76
- self.class.handler_registry.each do |handler|
77
- logger.info(tag: :*) { "Handler: #{handler.name} (Category: #{category}, Consumer: #{self.class.name})" }
78
- end
79
-
80
68
  _, subscription_thread = ::Actor::Start.(subscription)
81
69
 
82
70
  actor_address, actor_thread = Actor.start(self, subscription, include: :thread)
@@ -87,24 +75,76 @@ module Consumer
87
75
  probe.(self, [actor_thread, subscription_thread], [actor_address, subscription_address])
88
76
  end
89
77
 
90
- logger.info(tag: :*) { "Started consumer: #{self.class.name} (Category: #{category}, Identifier: #{identifier || '(none)'}, Position: #{subscription.position})" }
78
+ logger.info(tags: [:consumer, :start]) { "Started consumer: #{self.class.name} (Category: #{category}, Identifier: #{identifier || '(none)'}, Position: #{subscription.position})" }
91
79
 
92
80
  AsyncInvocation::Incorrect
93
81
  end
94
82
 
83
+ def print_info
84
+ STDOUT.puts
85
+ STDOUT.puts " Consumer: #{self.class.name}"
86
+ STDOUT.puts " Category: #{category}"
87
+ STDOUT.puts " Position: #{subscription.position}"
88
+ STDOUT.puts " Identifier: #{identifier || '(none)'}"
89
+
90
+ print_startup_info if respond_to?(:print_startup_info)
91
+
92
+ STDOUT.puts " Position Location: #{position_store.location || '(none)'}"
93
+
94
+ STDOUT.puts
95
+
96
+ STDOUT.puts " Handlers:"
97
+ self.class.handler_registry.each do |handler|
98
+ STDOUT.puts " Handler: #{handler.name}"
99
+ STDOUT.puts " Messages: #{handler.message_registry.message_types.join(', ')}"
100
+ end
101
+ end
102
+
103
+ def log_info
104
+ logger.info(tags: [:consumer, :start]) { "Category: #{category} (Consumer: #{self.class.name})" }
105
+ logger.info(tags: [:consumer, :start]) { "Position: #{subscription.position} (Consumer: #{self.class.name})" }
106
+ logger.info(tags: [:consumer, :start]) { "Identifier: #{identifier || 'nil'} (Consumer: #{self.class.name})" }
107
+
108
+ log_startup_info if respond_to?(:log_startup_info)
109
+
110
+ logger.info(tags: [:consumer, :start]) { "Position Update Interval: #{position_update_interval.inspect} (Consumer: #{self.class.name})" }
111
+
112
+ logger.info(tags: [:consumer, :start]) { "Poll Interval Milliseconds: #{poll_interval_milliseconds.inspect} (Consumer: #{self.class.name})" }
113
+
114
+ self.class.handler_registry.each do |handler|
115
+ logger.info(tags: [:consumer, :start]) { "Handler: #{handler.name} (Consumer: #{self.class.name})" }
116
+ logger.info(tags: [:consumer, :start]) { "Messages: #{handler.message_registry.message_types.join(', ')} (Handler: #{handler.name}, Consumer: #{self.class.name})" }
117
+ end
118
+ end
119
+
120
+ def dispatch(message_data)
121
+ logger.trace(tags: [:consumer, :dispatch, :message]) { "Dispatching message (#{LogText.message_data(message_data)})" }
122
+
123
+ self.class.handler_registry.each do |handler|
124
+ handler.(message_data, session: session, settings: supplemental_settings)
125
+ end
126
+
127
+ update_position(message_data.global_position)
128
+
129
+ logger.debug(tags: [:consumer, :dispatch, :message]) { "Message dispatched (#{LogText.message_data(message_data)})" }
130
+ rescue => error
131
+ logger.error(tag: :*) { "Error raised (Error Class: #{error.class}, Error Message: #{error.message}, #{LogText.message_data(message_data)})" }
132
+ error_raised(error, message_data)
133
+ end
134
+
95
135
  def update_position(position)
96
- logger.trace { "Updating position (Global Position: #{position}, Counter: #{position_update_counter}/#{position_update_interval})" }
136
+ logger.trace(tags: [:consumer, :position]) { "Updating position (Global Position: #{position}, Counter: #{position_update_counter}/#{position_update_interval})" }
97
137
 
98
138
  self.position_update_counter += 1
99
139
 
100
140
  if position_update_counter >= position_update_interval
101
141
  position_store.put(position)
102
142
 
103
- logger.debug { "Updated position (Global Position: #{position}, Counter: #{position_update_counter}/#{position_update_interval})" }
143
+ logger.debug(tags: [:consumer, :position]) { "Updated position (Global Position: #{position}, Counter: #{position_update_counter}/#{position_update_interval})" }
104
144
 
105
145
  self.position_update_counter = 0
106
146
  else
107
- logger.debug { "Interval not reached; position not updated (Global Position: #{position}, Counter: #{position_update_counter}/#{position_update_interval})" }
147
+ logger.debug(tags: [:consumer, :position]) { "Interval not reached; position not updated (Global Position: #{position}, Counter: #{position_update_counter}/#{position_update_interval})" }
108
148
  end
109
149
  end
110
150
 
@@ -116,7 +156,7 @@ module Consumer
116
156
 
117
157
  module Configure
118
158
  def configure(**kwargs)
119
- logger.trace { "Configuring (Category: #{category})" }
159
+ logger.trace(tag: :consumer) { "Configuring (Category: #{category})" }
120
160
 
121
161
  super(**kwargs)
122
162
 
@@ -129,18 +169,26 @@ module Consumer
129
169
  poll_interval_milliseconds: poll_interval_milliseconds
130
170
  )
131
171
 
132
- logger.debug { "Done configuring (Category: #{category}, Starting Position: #{starting_position})" }
172
+ logger.debug(tag: :consumer) { "Done configuring (Category: #{category}, Starting Position: #{starting_position})" }
133
173
  end
134
174
  end
135
175
 
136
176
  module Build
137
- def build(category, position_update_interval: nil, poll_interval_milliseconds: nil, identifier: nil, **arguments)
177
+ def build(category, position_update_interval: nil, poll_interval_milliseconds: nil, identifier: nil, supplemental_settings: nil, **arguments)
138
178
  instance = new(category)
139
179
 
140
- unless identifier.nil?
180
+ if not identifier.nil?
141
181
  instance.identifier = identifier
142
182
  end
143
183
 
184
+ if not supplemental_settings.nil?
185
+ if not supplemental_settings.is_a?(::Settings)
186
+ supplemental_settings = ::Settings.build(supplemental_settings)
187
+ end
188
+
189
+ instance.supplemental_settings = supplemental_settings
190
+ end
191
+
144
192
  instance.position_update_interval = position_update_interval
145
193
  instance.poll_interval_milliseconds = poll_interval_milliseconds
146
194
 
@@ -185,4 +233,24 @@ module Consumer
185
233
  end
186
234
  end
187
235
  end
236
+
237
+ module Defaults
238
+ def self.startup_info?
239
+ StartupInfo.get == 'on'
240
+ end
241
+
242
+ module StartupInfo
243
+ def self.get
244
+ ENV.fetch(env_var, default)
245
+ end
246
+
247
+ def self.env_var
248
+ 'STARTUP_INFO'
249
+ end
250
+
251
+ def self.default
252
+ 'on'
253
+ end
254
+ end
255
+ end
188
256
  end
@@ -1,3 +1,4 @@
1
+ require 'settings/controls'
1
2
  require 'messaging/controls'
2
3
 
3
4
  require 'consumer/controls/category'
@@ -11,7 +12,7 @@ require 'consumer/controls/id'
11
12
  require 'consumer/controls/identifier'
12
13
  require 'consumer/controls/position'
13
14
  require 'consumer/controls/session'
14
- require 'consumer/controls/stream_name'
15
+ require 'consumer/controls/settings'
15
16
 
16
17
  require 'consumer/controls/position_store'
17
18
  require 'consumer/controls/position_store/file'
@@ -19,6 +20,7 @@ require 'consumer/controls/subscription'
19
20
 
20
21
  require 'consumer/controls/handle'
21
22
  require 'consumer/controls/handle/raise_error'
23
+ require 'consumer/controls/handle/settings'
22
24
 
23
25
  require 'consumer/controls/actor'
24
26
 
@@ -59,6 +59,14 @@ module Consumer
59
59
  end
60
60
 
61
61
  Example = self.example_class
62
+
63
+ module Settings
64
+ def self.example_class
65
+ Consumer.example_class(handlers: [Handle::Settings::Example])
66
+ end
67
+
68
+ Example = self.example_class
69
+ end
62
70
  end
63
71
  end
64
72
  end
@@ -15,7 +15,7 @@ module Consumer
15
15
  attr_accessor :failed_message
16
16
 
17
17
  handler Handle::Example
18
- handler Handle::RaiseError
18
+ handler Handle::RaiseError::Example
19
19
 
20
20
  def error_raised(error, message)
21
21
  self.handled_error = error
@@ -22,6 +22,10 @@ module Consumer
22
22
  instance
23
23
  end
24
24
 
25
+ def category
26
+ Category.example
27
+ end
28
+
25
29
  def batch_size
26
30
  Defaults.batch_size
27
31
  end
@@ -0,0 +1,7 @@
1
+ module Consumer
2
+ module Controls
3
+ module Handle
4
+ Settings = ::Messaging::Controls::Handler::Settings
5
+ end
6
+ end
7
+ end
@@ -1,20 +1,35 @@
1
1
  module Consumer
2
2
  module Controls
3
3
  module PositionStore
4
- def self.example
5
- Example.build
4
+ def self.example(&block)
5
+ if block.nil?
6
+ cls = Example
7
+ else
8
+ cls = example_class(&block)
9
+ end
10
+
11
+ cls.build
6
12
  end
7
13
 
8
- class Example
9
- include ::Consumer::PositionStore
14
+ def self.example_class(&block)
15
+ Class.new do
16
+ include ::Consumer::PositionStore
10
17
 
11
- attr_accessor :telemetry_sink
18
+ def self.build
19
+ instance = new
20
+ instance.configure
21
+ instance
22
+ end
12
23
 
13
- def self.build
14
- instance = new
15
- instance.configure
16
- instance
24
+ def configure
25
+ end
26
+
27
+ class_exec(&block) unless block.nil?
17
28
  end
29
+ end
30
+
31
+ Example = example_class do
32
+ attr_accessor :telemetry_sink
18
33
 
19
34
  def configure
20
35
  self.telemetry_sink = ::Consumer::PositionStore::Telemetry::Sink.new
@@ -29,6 +44,12 @@ module Consumer
29
44
  def put(_)
30
45
  end
31
46
  end
47
+
48
+ module Location
49
+ def self.example
50
+ 'somePositionStream'
51
+ end
52
+ end
32
53
  end
33
54
  end
34
55
  end
@@ -0,0 +1,13 @@
1
+ module Consumer
2
+ module Controls
3
+ module Settings
4
+ def self.example
5
+ ::Settings.build(data)
6
+ end
7
+
8
+ def self.data
9
+ ::Settings::Controls::Data::Flat::Single.example
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,6 +3,7 @@ module Consumer
3
3
  def self.included(cls)
4
4
  cls.class_exec do
5
5
  include Dependency
6
+ include Virtual
6
7
  include Log::Dependency
7
8
 
8
9
  extend Build
@@ -13,6 +14,8 @@ module Consumer
13
14
  prepend Put
14
15
 
15
16
  dependency :telemetry, ::Telemetry
17
+
18
+ virtual :location
16
19
  end
17
20
  end
18
21
 
@@ -60,7 +63,7 @@ module Consumer
60
63
 
61
64
  position = super
62
65
 
63
- logger.info(tags: [:position_store, :get]) { "Get position done (Position: #{position || '(none)'})" }
66
+ logger.debug(tags: [:position_store, :get]) { "Get position done (Position: #{position || '(none)'})" }
64
67
 
65
68
  telemetry.record(:get, Telemetry::Get.new(position))
66
69
 
@@ -6,6 +6,8 @@ module Consumer
6
6
  end
7
7
 
8
8
  class PositionStore
9
+ include Consumer::PositionStore
10
+
9
11
  attr_accessor :get_position
10
12
  attr_accessor :put_position
11
13
 
@@ -0,0 +1 @@
1
+ lib/consumer/Users/sbellware/projects/eventide/consumer-postgres/lib/consumer/postgres
@@ -0,0 +1 @@
1
+ lib/consumer/Users/sbellware/projects/eventide/consumer-postgres/lib/consumer/postgres.rb
@@ -53,7 +53,7 @@ module Consumer
53
53
  end
54
54
 
55
55
  if batch.nil? || batch.empty?
56
- logger.debug { "Did not resupply; no events available (Category: #{get.category}, Position: #{position})" }
56
+ logger.debug { "Did not resupply; no events available (Stream: #{get.stream_name}, Position: #{position})" }
57
57
 
58
58
  :resupply
59
59
  else
@@ -2,6 +2,9 @@ module Consumer
2
2
  class Subscription
3
3
  module Defaults
4
4
  def self.poll_interval_milliseconds
5
+ env_interval = ENV['POLL_INTERVAL_MILLISECONDS']
6
+ return env_interval.to_i if !env_interval.nil?
7
+
5
8
  100
6
9
  end
7
10
 
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: 2.2.0.0
4
+ version: 2.3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-10 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ntl-actor
@@ -114,6 +114,7 @@ files:
114
114
  - lib/consumer/controls/get/incrementing.rb
115
115
  - lib/consumer/controls/handle.rb
116
116
  - lib/consumer/controls/handle/raise_error.rb
117
+ - lib/consumer/controls/handle/settings.rb
117
118
  - lib/consumer/controls/id.rb
118
119
  - lib/consumer/controls/identifier.rb
119
120
  - lib/consumer/controls/message_data.rb
@@ -123,7 +124,7 @@ files:
123
124
  - lib/consumer/controls/position_store.rb
124
125
  - lib/consumer/controls/position_store/file.rb
125
126
  - lib/consumer/controls/session.rb
126
- - lib/consumer/controls/stream_name.rb
127
+ - lib/consumer/controls/settings.rb
127
128
  - lib/consumer/controls/subscription.rb
128
129
  - lib/consumer/defaults.rb
129
130
  - lib/consumer/handler_registry.rb
@@ -132,6 +133,8 @@ files:
132
133
  - lib/consumer/position_store.rb
133
134
  - lib/consumer/position_store/substitute.rb
134
135
  - lib/consumer/position_store/telemetry.rb
136
+ - lib/consumer/postgres
137
+ - lib/consumer/postgres.rb
135
138
  - lib/consumer/subscription.rb
136
139
  - lib/consumer/subscription/defaults.rb
137
140
  - lib/consumer/subscription/get_batch.rb
@@ -140,7 +143,7 @@ homepage: https://github.com/eventide-project/consumer
140
143
  licenses:
141
144
  - MIT
142
145
  metadata: {}
143
- post_install_message:
146
+ post_install_message:
144
147
  rdoc_options: []
145
148
  require_paths:
146
149
  - lib
@@ -155,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
158
  - !ruby/object:Gem::Version
156
159
  version: '0'
157
160
  requirements: []
158
- rubygems_version: 3.0.1
159
- signing_key:
161
+ rubygems_version: 3.1.2
162
+ signing_key:
160
163
  specification_version: 4
161
164
  summary: Continuous subscription to a category and message dispatching to handlers
162
165
  test_files: []
@@ -1,6 +0,0 @@
1
- ## Consider whether this is still needed after category rename
2
- module Consumer
3
- module Controls
4
- StreamName = Messaging::Controls::StreamName
5
- end
6
- end