evt-consumer 0.2.1.0 → 0.3.0.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
  SHA1:
3
- metadata.gz: 2d8a67363fe73b9f14487853b768ae7c7517a8cf
4
- data.tar.gz: 186fe59a8acbbf419b705b88a343fd87e07a84e4
3
+ metadata.gz: e1d54c15b94cdb4d5f1bca14b2bef0d35a1d8e82
4
+ data.tar.gz: 2e44a08b424289ba4225fdbdd6ff7c73e91e3842
5
5
  SHA512:
6
- metadata.gz: 49ac045f2b5f46c4d4ced49a8fb7cab179be64efb2bedf80502d4a175d6b6ef3dd2f80bd25f5e51704cbc963c9f2fddbecd61a39f0e4e857c6584e82be5cf78c
7
- data.tar.gz: 50fc32c50bf55ea29a308afcc3c15e46239396d151a7717e53ad2d636c99e1ca5b3ef108adfd252f06d4887063ff47e5244353276d7c221e7c58817024e46a84
6
+ metadata.gz: 20ea5da08362f78ef225d55b8ccc9e7994db823b7d2914e3675812e8e68d8d6011628c83ff91177320bffae50a0044d2a820dde568b9ef1105f3c2f620e09827
7
+ data.tar.gz: 8999009e287a384350d799f93f91cebb1e74d8a9279dbf86db34d1577fdbd6c134366a28b4ced2b3bab416d93f1ee3bebe1ffe84a1ba446a7a07d389b7bcd697
@@ -8,13 +8,15 @@ module Consumer
8
8
  extend Start
9
9
 
10
10
  extend HandleMacro
11
- extend PositionStoreMacro
12
11
 
13
12
  prepend Configure
14
13
 
15
14
  initializer :stream
16
15
 
17
16
  attr_writer :position_update_interval
17
+ def position_update_interval
18
+ @position_update_interval ||= Defaults.position_update_interval
19
+ end
18
20
 
19
21
  attr_accessor :cycle_maximum_milliseconds
20
22
  attr_accessor :cycle_timeout_milliseconds
@@ -67,18 +69,12 @@ module Consumer
67
69
  end
68
70
 
69
71
  module Configure
70
- def configure(batch_size: nil, session: nil)
72
+ def configure(batch_size: nil, session: nil, position_store: nil)
71
73
  logger.trace { "Configuring (Batch Size: #{batch_size}, Session: #{session.inspect})" }
72
74
 
73
75
  super if defined? super
74
76
 
75
- position_store_class = self.class.position_store_class
76
-
77
- unless position_store_class.nil?
78
- position_store = position_store_class.configure self, stream
79
-
80
- starting_position = position_store.get
81
- end
77
+ starting_position = self.position_store.get
82
78
 
83
79
  subscription = Subscription.configure(
84
80
  self,
@@ -96,13 +92,14 @@ module Consumer
96
92
  end
97
93
 
98
94
  module Build
99
- def build(stream_name, batch_size: nil, session: nil, cycle_timeout_milliseconds: nil, cycle_maximum_milliseconds: nil)
100
- stream = EventSource::Stream.canonize stream_name
95
+ def build(stream_name, batch_size: nil, position_store: nil, position_update_interval: nil, session: nil, cycle_timeout_milliseconds: nil, cycle_maximum_milliseconds: nil)
96
+ stream = EventSource::Stream.build stream_name
101
97
 
102
98
  instance = new stream
99
+ instance.position_update_interval = position_update_interval
103
100
  instance.cycle_maximum_milliseconds = cycle_maximum_milliseconds
104
101
  instance.cycle_timeout_milliseconds = cycle_timeout_milliseconds
105
- instance.configure batch_size: batch_size, session: session
102
+ instance.configure batch_size: batch_size, position_store: position_store, session: session
106
103
  instance
107
104
  end
108
105
  end
@@ -162,23 +159,4 @@ module Consumer
162
159
  @handler_registry ||= HandlerRegistry.new
163
160
  end
164
161
  end
165
-
166
- module PositionStoreMacro
167
- def self.extended(cls)
168
- cls.singleton_class.class_exec do
169
- attr_accessor :position_store_class
170
- attr_writer :position_update_interval
171
-
172
- def position_update_interval
173
- @position_update_interval ||= Defaults.position_update_interval
174
- end
175
- end
176
- end
177
-
178
- def position_store_macro(position_store_class, update_interval: nil)
179
- self.position_store_class = position_store_class
180
- self.position_update_interval = update_interval
181
- end
182
- alias_method :position_store, :position_store_macro
183
- end
184
162
  end
@@ -18,4 +18,4 @@ require 'consumer/controls/position_store/local_file'
18
18
  require 'consumer/controls/subscription'
19
19
 
20
20
  require 'consumer/controls/consumer'
21
- require 'consumer/controls/consumer/logs_events'
21
+ require 'consumer/controls/consumer/incrementing'
@@ -9,10 +9,10 @@ module Consumer
9
9
  include ::Consumer
10
10
 
11
11
  handle Handle::Example
12
- position_store PositionStore::Example
13
12
 
14
- def configure(session: nil, batch_size: nil)
13
+ def configure(session: nil, batch_size: nil, position_store: nil)
15
14
  Get::Example.configure self
15
+ PositionStore::Example.configure self, position_store: position_store
16
16
  end
17
17
  end
18
18
  end
@@ -1,7 +1,7 @@
1
1
  module Consumer
2
2
  module Controls
3
3
  module Consumer
4
- class LogsEvents
4
+ class Incrementing
5
5
  include ::Consumer
6
6
 
7
7
  def self.logger
@@ -16,13 +16,13 @@ module Consumer
16
16
  logger.debug { event_data.data.pretty_inspect }
17
17
  end
18
18
 
19
- position_store PositionStore::LocalFile, update_interval: 10
20
-
21
- def configure(session: nil, batch_size: nil)
19
+ def configure(session: nil, batch_size: nil, position_store: nil)
22
20
  sleep_duration = ENV['SLEEP_DURATION'] || 100
23
21
  sleep_duration = sleep_duration.to_i
24
22
 
25
23
  Get::Incrementing.configure self, sleep_duration
24
+
25
+ PositionStore::LocalFile.configure self, position_store: position_store
26
26
  end
27
27
  end
28
28
  end
@@ -2,9 +2,7 @@ module Consumer
2
2
  module Controls
3
3
  module PositionStore
4
4
  def self.example
5
- stream_name = StreamName.example
6
-
7
- Example.build stream_name
5
+ Example.build
8
6
  end
9
7
 
10
8
  class Example
@@ -5,33 +5,65 @@ module Consumer
5
5
  include Log::Dependency
6
6
 
7
7
  extend Build
8
+ extend ClassConfigure
8
9
 
10
+ prepend Configure
9
11
  prepend Get
10
12
  prepend Put
11
13
 
12
- configure :position_store
13
-
14
- initializer :stream
15
-
16
14
  dependency :telemetry, ::Telemetry
17
15
  end
18
16
  end
19
17
 
20
18
  Virtual::Method.define self, :configure
21
19
 
20
+ module Build
21
+ def build
22
+ instance = new
23
+ instance.configure
24
+ instance
25
+ end
26
+ end
27
+
28
+ module ClassConfigure
29
+ def configure(receiver, *arguments, position_store: nil, attr_name: nil, **keyword_arguments)
30
+ attr_name ||= :position_store
31
+
32
+ if position_store.nil?
33
+ if arguments.any?
34
+ position_store = build *arguments, **keyword_arguments
35
+ else
36
+ position_store = build *arguments
37
+ end
38
+ end
39
+
40
+ receiver.public_send "#{attr_name}=", position_store
41
+
42
+ position_store
43
+ end
44
+ end
45
+
46
+ module Configure
47
+ def configure
48
+ ::Telemetry.configure self
49
+
50
+ super
51
+ end
52
+ end
53
+
22
54
  module Get
23
55
  def self.prepended(cls)
24
56
  Virtual::PureMethod.define cls, :get
25
57
  end
26
58
 
27
59
  def get
28
- logger.trace { "Get position (Stream: #{stream.name})" }
60
+ logger.trace { "Get position" }
29
61
 
30
62
  position = super
31
63
 
32
- logger.debug { "Get position done (Stream: #{stream.name}, Position: #{position})" }
64
+ logger.debug { "Get position done (Position: #{position})" }
33
65
 
34
- telemetry.record :get, Telemetry::Get.new(position, stream)
66
+ telemetry.record :get, Telemetry::Get.new(position)
35
67
 
36
68
  position
37
69
  end
@@ -43,27 +75,16 @@ module Consumer
43
75
  end
44
76
 
45
77
  def put(position)
46
- logger.trace { "Put position (Stream: #{stream.name}, Position: #{position})" }
78
+ logger.trace { "Put position (Position: #{position})" }
47
79
 
48
80
  super
49
81
 
50
- logger.debug { "Put position done (Stream: #{stream.name}, Position: #{position})" }
82
+ logger.debug { "Put position done (Position: #{position})" }
51
83
 
52
- telemetry.record :put, Telemetry::Put.new(position, stream)
84
+ telemetry.record :put, Telemetry::Put.new(position)
53
85
 
54
86
  nil
55
87
  end
56
88
  end
57
-
58
- module Build
59
- def build(stream)
60
- stream = EventSource::Stream.canonize stream
61
-
62
- instance = new stream
63
- ::Telemetry.configure instance
64
- instance.configure
65
- instance
66
- end
67
- end
68
89
  end
69
90
  end
@@ -8,8 +8,8 @@ module Consumer
8
8
  record :put
9
9
  end
10
10
 
11
- Get = Struct.new :position, :stream
12
- Put = Struct.new :position, :stream
11
+ Get = Struct.new :position
12
+ Put = Struct.new :position
13
13
  end
14
14
  end
15
15
  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.2.1.0
4
+ version: 0.3.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-01-23 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ntl-actor
@@ -78,7 +78,7 @@ files:
78
78
  - lib/consumer/controls.rb
79
79
  - lib/consumer/controls/category.rb
80
80
  - lib/consumer/controls/consumer.rb
81
- - lib/consumer/controls/consumer/logs_events.rb
81
+ - lib/consumer/controls/consumer/incrementing.rb
82
82
  - lib/consumer/controls/cycle.rb
83
83
  - lib/consumer/controls/error.rb
84
84
  - lib/consumer/controls/event_data.rb