pg_eventstore 1.3.4 → 1.4.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
  SHA256:
3
- metadata.gz: 66aeaf1c1365b962133efe784a507722fe0be9c80cb1911edd76512cb7a1af17
4
- data.tar.gz: 34ebc698b212e0631f005f754bbcf808f95796c149f969a1466ede8c7842e362
3
+ metadata.gz: 80f70b0a0704b224854bda8c4d0a5ffeba9dad355cb44233e84146ece3dcc9fc
4
+ data.tar.gz: '0682683f6b68f27dbf9ec88af1804ff82995ebb899c56ea40595b79ab68afe48'
5
5
  SHA512:
6
- metadata.gz: ad3c0661aa7c995c357588cbbaa4c9958868068ec452284250f41e0c2e3ae98eabdae837e7c00e63e59f22df7c5920aef2ad1497340d99dcc5bdc8e3e98ffb1f
7
- data.tar.gz: 395e5697dad7945e3c5bc2b51956195097aca503e9e20445b0d3b857fcdb17e4074ec392dc8fdf8a840e132e7f353093985e715a521ef7c73db5b902e0bcbffb
6
+ metadata.gz: 47adc4ffc8200caf20e26ce4e436c3f5609e78f378fd1345639c56d39db2af7489a7790e7924c9c4316055771424aae062eb4a55ee3070d82d12f80411aa5198
7
+ data.tar.gz: 0b512311767198a395897f27177e2c9e24280d99763f2aa23cd40021d2969c6d0a93886240a3407ea9ef4067f7d26847fe6b349bcab9040df64bf16f4a8058a7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0]
4
+ - Add an ability to configure subscription graceful shutdown timeout globally and per subscription. Default value is 15 seconds. Previously it was hardcoded to 5 seconds. Examples:
5
+
6
+ ```ruby
7
+ # Set it globally, for all subscriptions
8
+ PgEventstore.configure do |config|
9
+ config.subscription_graceful_shutdown_timeout = 5
10
+ end
11
+
12
+ # Set it per subscription
13
+ subscriptions_manager.subscribe(
14
+ 'MySubscriptionWithHeavyLiftingTask',
15
+ handler: proc { |event| puts event },
16
+ graceful_shutdown_timeout: 20
17
+ )
18
+ ```
19
+
3
20
  ## [1.3.4]
4
21
  - Fix `NoMethodError` error in `Client#read_paginated` when stream does not exist or when there are no events matching the given filter
5
22
 
@@ -2,21 +2,22 @@
2
2
 
3
3
  Configuration options:
4
4
 
5
- | name | value | default value | description |
6
- |------------------------------------|---------|--------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7
- | pg_uri | String | `'postgresql://postgres:postgres@localhost:5432/eventstore'` | PostgreSQL connection string. See PostgreSQL [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS) for more information. |
8
- | max_count | Integer | `1000` | Number of events to return in one response when reading from a stream. |
9
- | middlewares | Array | `{}` | A hash where a key is a name of your middleware and value is an object that respond to `#serialize` and `#deserialize` methods. See [**Writing middleware**](writing_middleware.md) chapter. |
10
- | event_class_resolver | `#call` | `PgEventstore::EventClassResolver.new` | A `#call`-able object that accepts a string and returns an event's class. See **Resolving events classes** chapter bellow for more info. |
11
- | connection_pool_size | Integer | `5` | Max number of connections per ruby process. It must equal the number of threads of your application. When using subscriptions it is recommended to set it to the number of subscriptions divided by two or greater. See [**Picking max connections number**](#picking-max-connections-number) chapter of this section. |
12
- | connection_pool_timeout | Integer | `5` | Time in seconds to wait for a connection in the pool to be released. If no connections are available during this time - `ConnectionPool::TimeoutError` will be raised. See `connection_pool` gem [docs](https://github.com/mperham/connection_pool#usage) for more info. |
13
- | subscription_pull_interval | Float | `1.0` | How often to pull new subscription events in seconds. The minimum meaningful value is `0.2`. Values less than `0.2` will act as it is `0.2`. |
14
- | subscription_max_retries | Integer | `5` | Max number of retries of failed subscription. |
15
- | subscription_retries_interval | Integer | `1` | Interval in seconds between retries of failed subscriptions. |
16
- | subscriptions_set_max_retries | Integer | `10` | Max number of retries for failed subscription sets. |
17
- | subscriptions_set_retries_interval | Integer | `1` | Interval in seconds between retries of failed subscription sets. |
18
- | subscription_restart_terminator | `#call` | `nil` | A callable object that accepts `PgEventstore::Subscription` object to determine whether restarts should be stopped(true - stops restarts, false - continues restarts). |
19
- | failed_subscription_notifier | `#call` | `nil` | A callable object which is invoked with `PgEventstore::Subscription` instance and error instance after the related subscription died due to error and no longer can be automatically restarted due to max retries number reached. You can use this hook to send a notification about failed subscription. |
5
+ | name | value | default value | description |
6
+ |----------------------------------------|----------------|--------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7
+ | pg_uri | String | `'postgresql://postgres:postgres@localhost:5432/eventstore'` | PostgreSQL connection string. See PostgreSQL [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS) for more information. |
8
+ | max_count | Integer | `1000` | Number of events to return in one response when reading from a stream. |
9
+ | middlewares | Array | `{}` | A hash where a key is a name of your middleware and value is an object that respond to `#serialize` and `#deserialize` methods. See [**Writing middleware**](writing_middleware.md) chapter. |
10
+ | event_class_resolver | `#call` | `PgEventstore::EventClassResolver.new` | A `#call`-able object that accepts a string and returns an event's class. See **Resolving events classes** chapter bellow for more info. |
11
+ | connection_pool_size | Integer | `5` | Max number of connections per ruby process. It must equal the number of threads of your application. When using subscriptions it is recommended to set it to the number of subscriptions divided by two or greater. See [**Picking max connections number**](#picking-max-connections-number) chapter of this section. |
12
+ | connection_pool_timeout | Integer | `5` | Time in seconds to wait for a connection in the pool to be released. If no connections are available during this time - `ConnectionPool::TimeoutError` will be raised. See `connection_pool` gem [docs](https://github.com/mperham/connection_pool#usage) for more info. |
13
+ | subscription_pull_interval | Float | `1.0` | How often to pull new subscription events in seconds. The minimum meaningful value is `0.2`. Values less than `0.2` will act as it is `0.2`. |
14
+ | subscription_max_retries | Integer | `5` | Max number of retries of failed subscription. |
15
+ | subscription_retries_interval | Integer | `1` | Interval in seconds between retries of failed subscriptions. |
16
+ | subscriptions_set_max_retries | Integer | `10` | Max number of retries for failed subscription sets. |
17
+ | subscriptions_set_retries_interval | Integer | `1` | Interval in seconds between retries of failed subscription sets. |
18
+ | subscription_restart_terminator | `#call` | `nil` | A callable object that accepts `PgEventstore::Subscription` object to determine whether restarts should be stopped(true - stops restarts, false - continues restarts). |
19
+ | failed_subscription_notifier | `#call` | `nil` | A callable object which is invoked with `PgEventstore::Subscription` instance and error instance after the related subscription died due to error and no longer can be automatically restarted due to max retries number reached. You can use this hook to send a notification about failed subscription. |
20
+ | subscription_graceful_shutdown_timeout | Integer, Float | `15` | The number of seconds to wait until force-shutdown the subscription during the stop process. If your subscription handler does not finish current event processing during this time(for example because of heavy-lifting task) - it will be force-shutdown. |
20
21
 
21
22
  ## Multiple configurations
22
23
 
@@ -151,7 +151,7 @@ You will then see the output of your subscription handlers. To gracefully stop t
151
151
 
152
152
  ## Overriding Subscription config values
153
153
 
154
- You can override `subscription_pull_interval`, `subscription_max_retries`, `subscription_retries_interval`, `subscription_restart_terminator` and `failed_subscription_notifier` config values (see [**Configuration**](configuration.md) chapter for details) for the specific subscription by providing the corresponding arguments. Example:
154
+ You can override `subscription_pull_interval`, `subscription_max_retries`, `subscription_retries_interval`, `subscription_restart_terminator`, `failed_subscription_notifier` and `subscription_graceful_shutdown_timeout` config values (see [**Configuration**](configuration.md) chapter for details) for the specific subscription by providing the corresponding arguments. Example:
155
155
 
156
156
  ```ruby
157
157
  subscriptions_manager.subscribe(
@@ -166,7 +166,9 @@ subscriptions_manager.subscribe(
166
166
  # overrides config.subscription_restart_terminator
167
167
  restart_terminator: proc { |subscription| subscription.last_error['class'] == 'NoMethodError' },
168
168
  # overrides config.failed_subscription_notifier
169
- failed_subscription_notifier: proc { |_subscription, err| p err }
169
+ failed_subscription_notifier: proc { |_subscription, err| p err },
170
+ # overrides config.subscription_graceful_shutdown_timeout
171
+ graceful_shutdown_timeout: 20
170
172
  )
171
173
  ```
172
174
 
@@ -52,6 +52,9 @@ module PgEventstore
52
52
  # @return [#call, nil] provide callable object that accepts Subscription instance and error. It is useful when you
53
53
  # want to be get notified when your Subscription fails and no longer can be restarted
54
54
  option(:failed_subscription_notifier)
55
+ # @!attribute subscription_graceful_shutdown_timeout
56
+ # @return [Integer] the number of seconds to wait until force-shutdown the subscription during the stop process
57
+ option(:subscription_graceful_shutdown_timeout) { 15 }
55
58
 
56
59
  # @param name [Symbol] config's name. Its value matches the appropriate key in PgEventstore.config hash
57
60
  def initialize(name:, **options)
@@ -83,8 +83,8 @@ module PgEventstore
83
83
 
84
84
  # @param run_interval [Integer, Float] seconds. Determines how often to run async task. Async task is determined by
85
85
  # :after_runner_stopped callback
86
- # @param async_shutdown_time [Integer, Float] seconds. Determines how long to wait for the async shutdown to wait
87
- # for the runner to finish.
86
+ # @param async_shutdown_time [Integer, Float] seconds. Determines how long to wait before force-shutdown the runner.
87
+ # It is only meaningful for the #stop_async
88
88
  def initialize(run_interval, async_shutdown_time)
89
89
  @run_interval = run_interval
90
90
  @async_shutdown_time = async_shutdown_time
@@ -11,10 +11,12 @@ module PgEventstore
11
11
  :within_state
12
12
 
13
13
  # @param handler [#call]
14
- def initialize(handler)
14
+ # @param graceful_shutdown_timeout [Integer, Float] seconds. Determines how long to wait before force-shutdown
15
+ # the runner when stopping it using #stop_async
16
+ def initialize(handler, graceful_shutdown_timeout:)
15
17
  @handler = handler
16
18
  @raw_events = []
17
- @basic_runner = BasicRunner.new(0, 5)
19
+ @basic_runner = BasicRunner.new(0, graceful_shutdown_timeout)
18
20
  attach_runner_callbacks
19
21
  end
20
22
 
@@ -67,20 +67,25 @@ module PgEventstore
67
67
  # PgEventstore::Subscription instance and error instance after the related subscription died due to error and no
68
68
  # longer can be automatically restarted due to max retries number reached. You can use this hook to send a
69
69
  # notification about failed subscription.
70
+ # @param graceful_shutdown_timeout [integer, Float] the number of seconds to wait until force-shutdown the
71
+ # subscription during the stop process
70
72
  # @return [void]
71
73
  def subscribe(subscription_name, handler:, options: {}, middlewares: nil,
72
74
  pull_interval: config.subscription_pull_interval,
73
75
  max_retries: config.subscription_max_retries,
74
76
  retries_interval: config.subscription_retries_interval,
75
77
  restart_terminator: config.subscription_restart_terminator,
76
- failed_subscription_notifier: config.failed_subscription_notifier)
78
+ failed_subscription_notifier: config.failed_subscription_notifier,
79
+ graceful_shutdown_timeout: config.subscription_graceful_shutdown_timeout)
77
80
  subscription = Subscription.using_connection(config.name).new(
78
81
  set: @set_name, name: subscription_name, options: options, chunk_query_interval: pull_interval,
79
82
  max_restarts_number: max_retries, time_between_restarts: retries_interval
80
83
  )
81
84
  runner = SubscriptionRunner.new(
82
85
  stats: SubscriptionHandlerPerformance.new,
83
- events_processor: EventsProcessor.new(create_event_handler(middlewares, handler)),
86
+ events_processor: EventsProcessor.new(
87
+ create_event_handler(middlewares, handler), graceful_shutdown_timeout: graceful_shutdown_timeout
88
+ ),
84
89
  subscription: subscription,
85
90
  restart_terminator: restart_terminator,
86
91
  failed_subscription_notifier: failed_subscription_notifier
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PgEventstore
4
4
  # @return [String]
5
- VERSION = "1.3.4"
5
+ VERSION = "1.4.0"
6
6
  end
@@ -49,5 +49,7 @@ module PgEventstore
49
49
  attr_accessor subscriptions_set_max_retries: Integer
50
50
 
51
51
  attr_accessor subscriptions_set_retries_interval: Integer
52
+
53
+ attr_accessor subscription_graceful_shutdown_timeout: Integer | Float
52
54
  end
53
55
  end
@@ -4,7 +4,7 @@ module PgEventstore
4
4
  extend Forwardable
5
5
 
6
6
  # _@param_ `handler`
7
- %a{rbs:test:skip} def initialize: (_SubscriptionHandler handler) -> void
7
+ %a{rbs:test:skip} def initialize: (_SubscriptionHandler handler, graceful_shutdown_timeout: Float | Integer) -> void
8
8
 
9
9
  # _@param_ `raw_events`
10
10
  def feed: (::Array[::Hash[untyped, untyped]] raw_events) -> void
@@ -42,7 +42,8 @@ module PgEventstore
42
42
  ?max_retries: Integer,
43
43
  ?retries_interval: Integer | Float,
44
44
  ?restart_terminator: _RestartTerminator?,
45
- ?failed_subscription_notifier: _FailedSubscriptionNotifier?
45
+ ?failed_subscription_notifier: _FailedSubscriptionNotifier?,
46
+ ?graceful_shutdown_timeout: Integer | Float,
46
47
  ) -> void
47
48
 
48
49
  def subscriptions: () -> ::Array[PgEventstore::Subscription]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Dzyzenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-30 00:00:00.000000000 Z
11
+ date: 2024-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg