es-readmodel 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/es-readmodel.gemspec +1 -1
- data/lib/es_readmodel/stream.rb +12 -6
- data/lib/es_readmodel/subscriber.rb +17 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 461f2d34b19899740eb1194ff7490f732c39dfb8
|
4
|
+
data.tar.gz: b479dd0e94a125dc5b5044acd19beafdd7b28943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d82ee96b08c208e66cfbe668605b26b7f9e1f5e821dc3ce11eca2f2de06ae6795490964ecaa1c8ce334fb3237f3b1229192dd5ca172f901b7af6553d6afdeda1
|
7
|
+
data.tar.gz: 0655b6785ac8f859fefe171e3847198164e86fe99bfef05bc68e217d7fd7a4f4d27de46710f8c26c2ce343cec770a0e92d24ed2f1d23d520ed9dceb279bf06cb
|
data/README.md
CHANGED
@@ -7,11 +7,16 @@ It will receive two arguments -- the current state and the event.
|
|
7
7
|
The current state will be nil if no events have bee processed yet.
|
8
8
|
The reducer function must return the new state.
|
9
9
|
|
10
|
-
##
|
10
|
+
## Routes
|
11
|
+
|
12
|
+
At the moment every route handler must return a Hash.
|
13
|
+
(If you don't, the Api module will crash!)
|
14
|
+
|
15
|
+
## Example usage
|
11
16
|
|
12
17
|
```[ruby]
|
13
18
|
require 'rack/cors'
|
14
|
-
|
19
|
+
require 'es_readmodel'
|
15
20
|
require_relative './active_users'
|
16
21
|
require_relative './list_users'
|
17
22
|
require_relative './get_user_details'
|
data/es-readmodel.gemspec
CHANGED
data/lib/es_readmodel/stream.rb
CHANGED
@@ -12,11 +12,6 @@ module EsReadModel
|
|
12
12
|
@connection = connection
|
13
13
|
@listener = listener
|
14
14
|
@current_etag = nil
|
15
|
-
@listener.call({
|
16
|
-
level: 'info',
|
17
|
-
tag: 'connecting',
|
18
|
-
msg: "Connecting to #{head_uri} on #{connection}"
|
19
|
-
})
|
20
15
|
fetch_first_page(head_uri)
|
21
16
|
end
|
22
17
|
|
@@ -38,16 +33,27 @@ module EsReadModel
|
|
38
33
|
|
39
34
|
def fetch_first_page(uri)
|
40
35
|
back_off = 1
|
36
|
+
@listener.call({
|
37
|
+
level: 'info',
|
38
|
+
tag: 'fetchFirstPage.connecting',
|
39
|
+
msg: "Connecting to #{uri} on #{@connection}"
|
40
|
+
})
|
41
41
|
loop do
|
42
42
|
begin
|
43
43
|
fetch(uri)
|
44
44
|
last = @current_page.first_event_uri
|
45
45
|
fetch(last) if last
|
46
|
+
@listener.call({
|
47
|
+
level: 'info',
|
48
|
+
tag: 'fetchFirstPage.connected',
|
49
|
+
msg: "Connected to #{uri} on #{@connection}",
|
50
|
+
eventsWaiting: !@current_page.empty?
|
51
|
+
})
|
46
52
|
return
|
47
53
|
rescue Exception => ex
|
48
54
|
@listener.call({
|
49
55
|
level: 'error',
|
50
|
-
tag: '
|
56
|
+
tag: 'fetchFirstPage.error',
|
51
57
|
msg: "#{ex.class}: #{ex.message}. Retry in #{back_off}s."
|
52
58
|
})
|
53
59
|
sleep back_off
|
@@ -76,10 +76,26 @@ module EsReadModel
|
|
76
76
|
@status[:available] = true
|
77
77
|
@stream.wait_for_new_events
|
78
78
|
@status[:available] = false
|
79
|
+
num_events_processed = 0
|
79
80
|
@stream.each_event do |evt|
|
80
|
-
|
81
|
+
begin
|
82
|
+
@state = @reducer.call(@state, evt)
|
83
|
+
rescue Exception => ex
|
84
|
+
@listener.call({
|
85
|
+
level: 'error',
|
86
|
+
tag: 'reducer.error',
|
87
|
+
msg: "Error in reducer: #{ex.class}: #{ex.message}. Read model state not updated."
|
88
|
+
})
|
89
|
+
end
|
81
90
|
@status[:eventsReceived] = @status[:eventsReceived] + 1
|
91
|
+
num_events_processed += 1
|
82
92
|
end
|
93
|
+
@listener.call({
|
94
|
+
level: 'info',
|
95
|
+
tag: 'subscription.caughtUp',
|
96
|
+
msg: "Subscription to $all caught up",
|
97
|
+
eventsProcessed: num_events_processed
|
98
|
+
})
|
83
99
|
end
|
84
100
|
end
|
85
101
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es-readmodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|