pg_eventstore 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/db/migrations/7_change_subscriptions_chunk_query_interval_type.sql +2 -0
- data/docs/configuration.md +31 -11
- data/docs/subscriptions.md +1 -1
- data/lib/pg_eventstore/config.rb +2 -2
- data/lib/pg_eventstore/subscriptions/subscription.rb +1 -1
- data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +1 -1
- data/lib/pg_eventstore/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be890a0bd9b5ffdf7289b76b503cdb659157a3dfe387d906e96cb7d57fbb8e63
|
4
|
+
data.tar.gz: 182a72941b0d9a2d242e6e3cf6cebe623b992905912e42f3877af5f9d8acdd96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea65eb0d4ffc1287c95eaeb7e8e795701a692dd30d82356cbd10b4ca8217fd59f658dca7e758a5b63f6eb5e1ff69913d6bebc2f48c4449e12386dd483598a532
|
7
|
+
data.tar.gz: ff5184dd724271d1276986c8d639011182a857cf65f08fe293b9f030ee14df9b18b4dfae81ab8676191e1c124b4a1f30f61ff26f892a6008ec6af6c95203df6c
|
data/CHANGELOG.md
CHANGED
data/docs/configuration.md
CHANGED
@@ -10,15 +10,18 @@ Configuration options:
|
|
10
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
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
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 |
|
13
|
+
| subscription_pull_interval | Float | `1.0` | How often to pull new subscription events in seconds. |
|
14
14
|
| subscription_max_retries | Integer | `5` | Max number of retries of failed subscription. |
|
15
15
|
| subscription_retries_interval | Integer | `1` | Interval in seconds between retries of failed subscriptions. |
|
16
16
|
| subscriptions_set_max_retries | Integer | `10` | Max number of retries for failed subscription sets. |
|
17
|
-
| subscriptions_set_retries_interval | Integer | `1` |
|
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). |
|
18
19
|
|
19
20
|
## Multiple configurations
|
20
21
|
|
21
|
-
`pg_eventstore` allows you to have as many configs as you want. This allows you, for example, to have different
|
22
|
+
`pg_eventstore` allows you to have as many configs as you want. This allows you, for example, to have different
|
23
|
+
databases, or to have a different set of middlewares for specific cases only. To do so, you have to name your
|
24
|
+
configuration, and later provide that name to `PgEventstore` client.
|
22
25
|
|
23
26
|
Setup your configs:
|
24
27
|
|
@@ -44,7 +47,8 @@ PgEventstore.client(:pg_db_2).read(PgEventstore::Stream.all_stream)
|
|
44
47
|
|
45
48
|
### Default config
|
46
49
|
|
47
|
-
If you have one config only - you don't have to bother naming it or passing a config name to the client when performing
|
50
|
+
If you have one config only - you don't have to bother naming it or passing a config name to the client when performing
|
51
|
+
any operations. You can configure it as usual.
|
48
52
|
|
49
53
|
Setup your default config:
|
50
54
|
|
@@ -65,12 +69,16 @@ EventStoreClient.client.read(PgEventstore::Stream.all_stream)
|
|
65
69
|
|
66
70
|
## Resolving event classes
|
67
71
|
|
68
|
-
During the deserialization process `pg_eventstore` tries to pick the correct class for an event. By default it does it
|
72
|
+
During the deserialization process `pg_eventstore` tries to pick the correct class for an event. By default it does it
|
73
|
+
using the `PgEventstore::EventClassResolver` class. All it does is `Object.const_get(event_type)`. By default, if you
|
74
|
+
don't provide the `type` attribute for an event explicitly, it will grab the event's class name, meaning by default:
|
69
75
|
|
70
76
|
- event's type is event's class name
|
71
|
-
- when instantiating an event - `pg_eventstore` tries to lookup an event class based on the value of event's `type`
|
77
|
+
- when instantiating an event - `pg_eventstore` tries to lookup an event class based on the value of event's `type`
|
78
|
+
attribute with a fallback to `PgEventstore::Event` class
|
72
79
|
|
73
|
-
You can override the default event class resolver by providing any `#call`-able object. It should accept event's type
|
80
|
+
You can override the default event class resolver by providing any `#call`-able object. It should accept event's type
|
81
|
+
and return event's class based on it. Example:
|
74
82
|
|
75
83
|
```ruby
|
76
84
|
PgEventstore.configure do |config|
|
@@ -80,11 +88,21 @@ end
|
|
80
88
|
|
81
89
|
## Picking max connections number
|
82
90
|
|
83
|
-
A connection is hold from the connection pool to perform the request and it is released back to the connection pool once
|
91
|
+
A connection is hold from the connection pool to perform the request and it is released back to the connection pool once
|
92
|
+
the request is finished. If you run into the (theoretical) edge case, when all your application's threads (or
|
93
|
+
subscriptions) are performing `pg_eventstore` queries at the same time and all those queries take more
|
94
|
+
than `connection_pool_timeout` seconds to complete, you have to have `connection_pool_size` set to the exact amount of
|
95
|
+
your application's threads (or to the number of subscriptions when using subscriptions) to prevent timeout errors.
|
96
|
+
Practically this is not the case, as all `pg_eventstore` queries are pretty fast. So, a good value for
|
97
|
+
the `connection_pool_size` option is **half the number ** of your application's threads(or half the number of
|
98
|
+
Subscriptions).
|
84
99
|
|
85
100
|
### Exception scenario
|
86
101
|
|
87
|
-
If you are using the [`#multiple`](multiple_commands.md) method - you have to take into account the execution time of
|
102
|
+
If you are using the [`#multiple`](multiple_commands.md) method - you have to take into account the execution time of
|
103
|
+
the whole block you pass in it. This is because the connection will be released only after the block's execution is
|
104
|
+
finished. So, for example, if you perform several commands within the block, as well as some API request, the connection
|
105
|
+
will be release only after all those steps:
|
88
106
|
|
89
107
|
```ruby
|
90
108
|
PgEventstore.client.multiple do
|
@@ -96,8 +114,10 @@ PgEventstore.client.multiple do
|
|
96
114
|
end
|
97
115
|
```
|
98
116
|
|
99
|
-
Taking this into account you may want to increase `connection_pool_size` up to the number of your application's threads(
|
117
|
+
Taking this into account you may want to increase `connection_pool_size` up to the number of your application's threads(
|
118
|
+
or subscriptions).
|
100
119
|
|
101
120
|
### Usage of external connection pooler
|
102
121
|
|
103
|
-
`pg_eventstore` does not use any session-specific features of PostgreSQL. You can use any PostgreSQL connection pooler
|
122
|
+
`pg_eventstore` does not use any session-specific features of PostgreSQL. You can use any PostgreSQL connection pooler
|
123
|
+
you like, such as [PgBouncer](https://www.pgbouncer.org/) for example.
|
data/docs/subscriptions.md
CHANGED
@@ -135,7 +135,7 @@ subscriptions_manager.subscribe(
|
|
135
135
|
'MyAwesomeSubscription',
|
136
136
|
handler: proc { |event| puts event },
|
137
137
|
# overrides config.subscription_pull_interval
|
138
|
-
pull_interval:
|
138
|
+
pull_interval: 0.5,
|
139
139
|
# overrides config.subscription_max_retries
|
140
140
|
max_retries: 10,
|
141
141
|
# overrides config.subscription_retries_interval
|
data/lib/pg_eventstore/config.rb
CHANGED
@@ -30,8 +30,8 @@ module PgEventstore
|
|
30
30
|
# @return [Integer] Time in seconds to wait for the connection in pool to be released
|
31
31
|
option(:connection_pool_timeout) { 5 }
|
32
32
|
# @!attribute subscription_pull_interval
|
33
|
-
# @return [
|
34
|
-
option(:subscription_pull_interval) {
|
33
|
+
# @return [Float] How often Subscription should pull new events, seconds
|
34
|
+
option(:subscription_pull_interval) { 1.0 }
|
35
35
|
# @!attribute subscription_max_retries
|
36
36
|
# @return [Integer] max number of retries of failed Subscription
|
37
37
|
option(:subscription_max_retries) { 100 }
|
@@ -53,7 +53,7 @@ module PgEventstore
|
|
53
53
|
# @return [Time, nil] the time when the last error occurred
|
54
54
|
attribute(:last_error_occurred_at)
|
55
55
|
# @!attribute chunk_query_interval
|
56
|
-
# @return [
|
56
|
+
# @return [Float] determines how often to pull events for the given Subscription in seconds
|
57
57
|
attribute(:chunk_query_interval)
|
58
58
|
# @!attribute chunk_query_interval
|
59
59
|
# @return [Time] shows the time when last time events were fed to the event's processor
|
@@ -50,7 +50,7 @@ module PgEventstore
|
|
50
50
|
# @param pull_interval [Integer] an interval in seconds to determine how often to query new events of the given
|
51
51
|
# subscription.
|
52
52
|
# @param max_retries [Integer] max number of retries of failed Subscription
|
53
|
-
# @param retries_interval [
|
53
|
+
# @param retries_interval [Float] a delay between retries of failed Subscription
|
54
54
|
# @param restart_terminator [#call, nil] a callable object which, when called - accepts PgEventstore::Subscription
|
55
55
|
# object to determine whether restarts should be stopped(true - stops restarts, false - continues restarts)
|
56
56
|
# @return [void]
|
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: 0.
|
4
|
+
version: 0.8.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-02-
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- db/migrations/4_create_subscriptions.sql
|
57
57
|
- db/migrations/5_create_subscription_commands.sql
|
58
58
|
- db/migrations/6_create_subscriptions_set_commands.sql
|
59
|
+
- db/migrations/7_change_subscriptions_chunk_query_interval_type.sql
|
59
60
|
- docs/appending_events.md
|
60
61
|
- docs/configuration.md
|
61
62
|
- docs/events_and_streams.md
|