evt-consumer-event_store 0.0.1.0 → 0.1.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: 7cd3ece855019e3f5506c094754da098ecc65c3b
4
- data.tar.gz: 0deb54dd7c937882f651d7f77ec3431e15c70706
3
+ metadata.gz: ecbcf1c2cc9462f85d925ec840c42526f7594861
4
+ data.tar.gz: 382ab57e19bd27af87a8967ec83a4e4734e91bd0
5
5
  SHA512:
6
- metadata.gz: 26f6803f9d8dec27abe972887562533d52cb9a9a355c33a090a6a62d9d17d2f67338a3d7afe4f74434d2bb7e25a14313e68adb3914219472e631672cc762663c
7
- data.tar.gz: 72ef57e3d7f2d47a71dd6a280e5fd29d6dad714bd7b87c3f9ce34bd35305b90156c8ea38de9de1c6f282647e28ad772442ae6e6fd9f16348b92388dae56ce158
6
+ metadata.gz: 4131ba217f00e3a07a29c0038bf47340003d1954224bcbda1a1e12603eb475f47b1466766a3f725cfe61bd591bcc248cda47dbd5f69245e5652bf739e33f2b19
7
+ data.tar.gz: 0c2272922b85c1a662147f0386f4048239a7517c66b5edf6c22c33d23a3b8fc05639b9c552345ee582219c4ae59b5fba7c1c47b40c5aac1ca922b7b2d3370978
@@ -3,5 +3,6 @@ require 'messaging/event_store'
3
3
 
4
4
  require 'consumer/event_store/event_store'
5
5
  require 'consumer/event_store/subscription'
6
+ require 'consumer/event_store/position_store'
6
7
 
7
8
  Consumer::EventStore.activate
@@ -3,6 +3,7 @@ require 'consumer/controls'
3
3
  require 'consumer/event_store/controls/category'
4
4
  require 'consumer/event_store/controls/event_data'
5
5
  require 'consumer/event_store/controls/handle'
6
+ require 'consumer/event_store/controls/position_stream'
6
7
  require 'consumer/event_store/controls/stream'
7
8
  require 'consumer/event_store/controls/stream_name'
8
9
 
@@ -0,0 +1,21 @@
1
+ module Consumer
2
+ module EventStore
3
+ module Controls
4
+ module PositionStream
5
+ module Write
6
+ def self.call(stream_name=nil, position: nil)
7
+ stream_name ||= StreamName.example type: 'position'
8
+ position ||= 0
9
+
10
+ message = PositionStore::PositionUpdated.new
11
+ message.position = position
12
+
13
+ Messaging::EventStore::Write.(message, stream_name)
14
+
15
+ return stream_name
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -21,6 +21,13 @@ module Consumer
21
21
  long_poll_duration: long_poll_duration,
22
22
  session: session
23
23
  )
24
+
25
+ PositionStore.configure(
26
+ self,
27
+ stream,
28
+ session: session,
29
+ position_store: position_store
30
+ )
24
31
  end
25
32
  end
26
33
  end
@@ -0,0 +1,66 @@
1
+ module Consumer
2
+ module EventStore
3
+ class PositionStore
4
+ include Consumer::PositionStore
5
+
6
+ initializer :stream_name
7
+
8
+ dependency :get_last, EventSource::EventStore::HTTP::Get::Last
9
+ dependency :session, EventSource::EventStore::HTTP::Session
10
+ dependency :write, ::Messaging::EventStore::Write
11
+
12
+ def self.build(stream_name, session: nil)
13
+ stream = EventSource::Stream.build stream_name
14
+
15
+ position_stream_name = StreamName.canonize stream.name
16
+
17
+ instance = new position_stream_name
18
+ EventSource::EventStore::HTTP::Session.configure instance, session: session
19
+ instance.configure
20
+ instance
21
+ end
22
+
23
+ def configure
24
+ EventSource::EventStore::HTTP::Get::Last.configure self, session: session
25
+ Messaging::EventStore::Write.configure self, session: session
26
+ end
27
+
28
+ def get
29
+ event_data = get_last.(stream_name)
30
+
31
+ return nil if event_data.nil?
32
+
33
+ message = Messaging::Message::Import.(event_data, PositionUpdated)
34
+ message.position
35
+ end
36
+
37
+ def put(position)
38
+ message = PositionUpdated.build :position => position
39
+
40
+ write.(message, stream_name)
41
+
42
+ message
43
+ end
44
+
45
+ class PositionUpdated
46
+ include Messaging::Message
47
+
48
+ attribute :position, Integer
49
+ end
50
+
51
+ module StreamName
52
+ def self.canonize(stream_name)
53
+ stream = EventSource::Stream.build stream_name
54
+
55
+ return stream.name if stream.type == 'position'
56
+
57
+ stream_name = "#{stream.category}:position"
58
+
59
+ stream_name << "-#{stream.id}" if stream.id
60
+
61
+ EventSource::EventStore::HTTP::StreamName.canonize stream_name
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-consumer-event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.0
4
+ version: 0.1.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-25 00:00:00.000000000 Z
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-consumer
@@ -64,9 +64,11 @@ files:
64
64
  - lib/consumer/event_store/controls/consumer.rb
65
65
  - lib/consumer/event_store/controls/event_data.rb
66
66
  - lib/consumer/event_store/controls/handle.rb
67
+ - lib/consumer/event_store/controls/position_stream.rb
67
68
  - lib/consumer/event_store/controls/stream.rb
68
69
  - lib/consumer/event_store/controls/stream_name.rb
69
70
  - lib/consumer/event_store/event_store.rb
71
+ - lib/consumer/event_store/position_store.rb
70
72
  - lib/consumer/event_store/subscription.rb
71
73
  homepage: https://github.com/eventide-project/consumer-event-store
72
74
  licenses: