event_store_client 1.1.5 → 1.2.1

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: 2624a6c8e08a686f5e307eccfb00ac9321eb5e2e32aed9093c0c67e8cb01b9e5
4
- data.tar.gz: 0b4ff333a547924f54aa182e0bb1f821a7382db93c5d9304038c43a514ee6d3b
3
+ metadata.gz: 3f3d458f2e88c538d11031447663da254409d7bd6b84212712f397b89958e34e
4
+ data.tar.gz: 9defe616729f3acef2163488e9ebd27b3f1e3ea66e803a81a80fde1c4cabff7c
5
5
  SHA512:
6
- metadata.gz: dfda05e2c763e85977c63a3b0e27034050b37c7ded273750b1aadec42e55fc459475c4a8d50167fe66952bb39c7145242ed017b5548abbece412beaa4e98d37a
7
- data.tar.gz: ca27251198df7d78a9b60482ee8dfef7f8b6cfdbda08d3a36f0af1723ee487b85239d0d046a6d777e5c6e5161725faaa4b4fac6aa3b650460eb622a428dc0960
6
+ metadata.gz: 4e1d867efa61641f5dbf0174c976790c7a08af97ad150902987b7a6d36a041e62f3eccd2bf4676f8f1be81e49dded5f6116c8be681f0291338780c487aaf00db
7
+ data.tar.gz: f9a0c5fc265ec88c3aedaa45a22671008336f7e0e11d1912322f2f3f197730e66b6980655abd7dd3d6c577528522b4bb40c2e429f900a85d06f464c0b150bc1a
@@ -84,10 +84,12 @@ module EventStoreClient
84
84
  #
85
85
  def listen(subscription, options: {})
86
86
  consume_feed(subscription, options: options) do |event|
87
- yield event if block_given?
87
+ begin
88
+ yield event if block_given?
89
+ rescue StandardError => e
90
+ config.error_handler&.call(e)
91
+ end
88
92
  end
89
- rescue StandardError => e
90
- config.error_handler&.call(e)
91
93
  end
92
94
 
93
95
  # Subscribe to a stream
@@ -9,6 +9,8 @@ module EventStoreClient
9
9
  class Command
10
10
  include Configuration
11
11
 
12
+ class GRPCUnavailableRetryFailed < StandardError; end
13
+
12
14
  def self.inherited(klass)
13
15
  super
14
16
  klass.class_eval do
@@ -27,9 +27,9 @@ module EventStoreClient
27
27
  'content-type': event_metadata['content-type']
28
28
  }
29
29
  custom_metadata['encryption'] = event_metadata['encryption'] unless event_metadata['encryption'].nil?
30
+ custom_metadata['transaction'] = event_metadata['transaction'] unless event_metadata['transaction'].nil?
30
31
  event_metadata = event_metadata.select { |k| ['type', 'content-type', 'created_at'].include?(k) }
31
32
 
32
-
33
33
  payload = [
34
34
  request.new(
35
35
  options: {
@@ -52,7 +52,7 @@ module EventStoreClient
52
52
  ]
53
53
  service.append(payload, metadata: metadata)
54
54
  end
55
- Success()
55
+ Success(events)
56
56
  end
57
57
  end
58
58
  end
@@ -44,10 +44,7 @@ module EventStoreClient
44
44
  end
45
45
 
46
46
  skip_decryption = options[:skip_decryption] || false
47
- events = service.read(request.new(options: opts), metadata: metadata).map do |res|
48
- raise StreamNotFound if res.stream_not_found
49
- deserialize_event(res.event.event, skip_decryption: skip_decryption)
50
- end
47
+ events = read_stream(opts, skip_decryption)
51
48
  Success(events)
52
49
  rescue StreamNotFound
53
50
  Failure(:not_found)
@@ -55,6 +52,18 @@ module EventStoreClient
55
52
 
56
53
  private
57
54
 
55
+ def read_stream(options, skip_decryption)
56
+ retries ||= 0
57
+ service.read(request.new(options: options), metadata: metadata).map do |res|
58
+ raise StreamNotFound if res.stream_not_found
59
+ deserialize_event(res.event.event, skip_decryption: skip_decryption)
60
+ end
61
+ rescue ::GRPC::Unavailable
62
+ sleep config.grpc_unavailable_retry_sleep
63
+ retry if (retries += 1) <= config.grpc_unavailable_retry_count
64
+ raise GRPCUnavailableRetryFailed
65
+ end
66
+
58
67
  def deserialize_event(entry, skip_decryption: false)
59
68
  data = (entry.data.nil? || entry.data.empty?) ? '{}' : entry.data
60
69
 
@@ -9,6 +9,8 @@ module EventStoreClient
9
9
  class Connection
10
10
  include Configuration
11
11
 
12
+ class SocketErrorRetryFailed < StandardError; end
13
+
12
14
  # Initializes the proper stub with the necessary credentials
13
15
  # to create working gRPC connection - Refer to generated grpc files
14
16
  # @return [Stub] Instance of a given `Stub` klass
@@ -29,6 +31,7 @@ module EventStoreClient
29
31
  attr_reader :cert
30
32
 
31
33
  def initialize
34
+ retries ||= 0
32
35
  @cert =
33
36
  Net::HTTP.start(
34
37
  config.eventstore_url.host, config.eventstore_url.port,
@@ -36,6 +39,10 @@ module EventStoreClient
36
39
  verify_mode: verify_ssl,
37
40
  &:peer_cert
38
41
  )
42
+ rescue SocketError
43
+ sleep config.socket_error_retry_sleep
44
+ retry if (retries += 1) <= config.socket_error_retry_count
45
+ raise SocketErrorRetryFailed
39
46
  end
40
47
 
41
48
  def channel_credentials
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dry/monads'
4
+
4
5
  module EventStoreClient
5
6
  class InMemory
6
7
  Response = Struct.new(:body, :status) do
@@ -22,7 +23,7 @@ module EventStoreClient
22
23
  'positionEventNumber' => event_store[stream_name].length
23
24
  )
24
25
  end
25
- Dry::Monads::Success()
26
+ Dry::Monads::Success(events)
26
27
  end
27
28
 
28
29
  def delete_stream(stream_name, options: {}) # rubocop:disable Lint/UnusedMethodArgument
@@ -12,6 +12,7 @@ module EventStoreClient
12
12
  def publish(stream:, events:, options: {})
13
13
  res = connection.append_to_stream(stream, events, options: options)
14
14
  raise WrongExpectedEventVersion.new(e.message) if res.failure?
15
+ res
15
16
  end
16
17
 
17
18
  def read(stream, options: {})
@@ -32,6 +32,12 @@ module EventStoreClient
32
32
 
33
33
  setting :logger
34
34
 
35
+ setting :socket_error_retry_sleep, 0.5
36
+ setting :socket_error_retry_count, 3
37
+
38
+ setting :grpc_unavailable_retry_sleep, 0.5
39
+ setting :grpc_unavailable_retry_count, 3
40
+
35
41
  def self.configure
36
42
  yield(config) if block_given?
37
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '1.1.5'
4
+ VERSION = '1.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2021-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -247,7 +247,7 @@ licenses:
247
247
  - MIT
248
248
  metadata:
249
249
  allowed_push_host: https://rubygems.org
250
- post_install_message:
250
+ post_install_message:
251
251
  rdoc_options: []
252
252
  require_paths:
253
253
  - lib
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  version: '0'
264
264
  requirements: []
265
265
  rubygems_version: 3.1.4
266
- signing_key:
266
+ signing_key:
267
267
  specification_version: 4
268
268
  summary: Ruby integration for https://eventstore.org
269
269
  test_files: []