evt-event_source-event_store-http 0.3.0.0 → 0.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
  SHA1:
3
- metadata.gz: 103accfc22fbead9cbb14c7ebc34caa3a835d121
4
- data.tar.gz: 7275b6f7d9334f8f8a1760a45ebb5819a9038adb
3
+ metadata.gz: 543311f455febc7a31b966da22504f6fec57b05f
4
+ data.tar.gz: 680e226ccdc840d38de17261049332de1a71db55
5
5
  SHA512:
6
- metadata.gz: 06ef8b13ec026bdc2f6f5d04b70694c3d12a13fe1477dc9269690b72418882890b140e09145212553b0c65468ceaf97ad1444844f4ab3661597cd24c177c77ea
7
- data.tar.gz: fae00c828d0bca010819a4e844e754946dada6852c4f71f472b6350afe4ec9e4ba4659b8d49b3e2dc53397aa2b86782bb936c7ab62d693a302e4eb4f68807796
6
+ metadata.gz: 3f0805dcb8ea8a90355834a4c63cde6baf882e2bce61a1d56ef5c658277a60f121647b5dfd3436e41b96c3c0656188d0dd4bc8ff597823e694236c7ae6c46cec
7
+ data.tar.gz: eac694421b5ab1d7102a9c0468404d49d48b3bb4aef34c99fcffdb76d4090794098d6dd90e186c4531a22d410df594f7b52efc4f6276a71d064e62168dcadfa0
@@ -6,7 +6,11 @@ module EventSource
6
6
 
7
7
  configure :get
8
8
 
9
- initializer :batch_size, :precedence, a(:long_poll_duration)
9
+ initializer :batch_size, w(:precedence), a(:long_poll_duration)
10
+
11
+ def precedence
12
+ @precedence ||= Defaults.precedence
13
+ end
10
14
 
11
15
  dependency :session, Session
12
16
  dependency :read_stream, ::EventStore::HTTP::ReadStream
@@ -14,7 +18,7 @@ module EventSource
14
18
  def self.build(batch_size: nil, precedence: nil, long_poll_duration: nil, session: nil)
15
19
  instance = new batch_size, precedence, long_poll_duration
16
20
  Session.configure instance, session: session
17
- ::EventStore::HTTP::ReadStream.configure instance
21
+ ::EventStore::HTTP::ReadStream.configure instance, session: session
18
22
  instance.configure
19
23
  instance
20
24
  end
@@ -34,12 +38,22 @@ module EventSource
34
38
  end
35
39
 
36
40
  def call(stream_name, position: nil)
37
- logger.trace { "Reading stream (StreamName: #{stream_name}, Position: #{position || '(start)'})" }
41
+ logger.trace { "Reading stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Direction: #{direction}, BatchSize: #{batch_size})" }
42
+
43
+ if precedence == :desc
44
+ position = desc_position stream_name, position
45
+
46
+ if position < 0
47
+ logger.debug { "Reading backward across start of stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Direction: #{direction}, BatchSize: #{batch_size}, Events: 0)" }
48
+ return []
49
+ end
50
+ end
38
51
 
39
52
  begin
40
53
  events = read_stream.(
41
54
  stream_name,
42
55
  position: position,
56
+ direction: direction,
43
57
  batch_size: batch_size
44
58
  )
45
59
  rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError
@@ -48,10 +62,43 @@ module EventSource
48
62
 
49
63
  events.reverse! if precedence == :desc
50
64
 
51
- logger.debug { "Done reading stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Events: #{events.count})" }
65
+ logger.debug { "Done reading stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Direction: #{direction}, BatchSize: #{batch_size}, Events: #{events.count})" }
52
66
 
53
67
  events
54
68
  end
69
+
70
+ def desc_position(stream_name, position)
71
+ begin
72
+ head_event, * = read_stream.(
73
+ stream_name,
74
+ position: :head,
75
+ direction: :backward,
76
+ batch_size: 1
77
+ )
78
+ rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError
79
+ return -1
80
+ end
81
+
82
+ if position.nil?
83
+ head_event.position
84
+ else
85
+ head_event.position - position
86
+ end
87
+ end
88
+
89
+ def direction
90
+ if precedence == :asc
91
+ :forward
92
+ else
93
+ :backward
94
+ end
95
+ end
96
+
97
+ module Defaults
98
+ def self.precedence
99
+ :asc
100
+ end
101
+ end
55
102
  end
56
103
  end
57
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-event_source-event_store-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.0
4
+ version: 0.3.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: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-event_source