pg_eventstore 1.1.4 → 1.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12384e5023ddd60d3ff1f70006dcc8cc44d7901e4ddc7c24fcf3ab3772a00daf
4
- data.tar.gz: d663c5aaaa96cee4f641710e7206938d9c8b06428c286b292edfaaecaaf0f4b1
3
+ metadata.gz: 5fce9f1f61310bfc9c12afdb89b0a6589e9116133255eeb62ac406b24e351b72
4
+ data.tar.gz: 0a03a441f9e26a040f026fc7fac5d034c81b91d6f0e0bee98646b39a2f809147
5
5
  SHA512:
6
- metadata.gz: e316a1a3d5a9619e4b9637aa411d9ff1cf438d4e210b02d7efd0b25e6bb1b865ff96f0cf8df2729715b5ec0b017b6254fbd51c6db9ad808b9c1a28717f7f65fc
7
- data.tar.gz: cfecd6d0c57422130233c1fce18dd94b978c577427684ccff0610c54c8951cfbea0d91904dabfdfc73dbc6b9568fbb1d04b955344cbb53eabc08edefee0b2d16
6
+ metadata.gz: 26a0a9b9cf70e32fd73d5f729d5d9654ec23cd90aa57a3bfdf4cae5603f58d56d62a1406df477200390497141e5c4bb89f157c749bd1df680c1b404898428094
7
+ data.tar.gz: 85aeeffcfc9ddfba2733e7362958a9d1528eb043ae5025c2d8bd055aa708e5c20eb2fef555be711174f3c058235c0f5b97c780b9f68b3a52e92592fe58d8f8c3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.5]
4
+ - Review the way to handle SubscriptionAlreadyLockedError error. This removes noise when attempting to lock an already locked subscription.
5
+
3
6
  ## [1.1.4]
4
7
  - Add rbs signatures
5
8
 
@@ -47,9 +47,23 @@ After you added all necessary subscriptions, it is time to start them:
47
47
 
48
48
  ```ruby
49
49
  subscriptions_manager.start
50
+ # => PgEventstore::BasicRunner
50
51
  ```
51
52
 
52
- After calling `#start` all subscriptions are locked behind the given subscription set and can't be locked by any other subscription set. This measure is needed to prevent running the same subscription under the same subscription set using different processes/subscription managers. Such situation will lead to a malformed subscription state and will break its position, meaning the same event will be processed several times.
53
+ After calling `#start` all subscriptions are locked behind the given subscriptions set and can't be locked by any other subscriptions set. This measure is needed to prevent running the same subscription under the same subscription set using different processes/subscription managers. Such situation will lead to a malformed subscription state and will break its position, meaning the same event will be processed several times. In real world the lock attempt may still happen. This can be common scenario when using kubernetes which rolls out new deployment before shutting down old one. In this case `#start` will return `nil`. You can use this behavior to properly handle such cases. Example:
54
+
55
+ ```ruby
56
+ timeout = 20 # 20 seconds
57
+ deadline = Time.now + timeout
58
+ loop do
59
+ break if subscriptions_manager.start
60
+ if Time.now > deadline
61
+ puts "Failed to acquire subscriptions lock within #{timeout} seconds. Exiting now."
62
+ exit
63
+ end
64
+ sleep 2
65
+ end
66
+ ```
53
67
 
54
68
  To "unlock" the subscription you should gracefully stop the subscription manager:
55
69
 
@@ -86,7 +100,16 @@ subscriptions_manager.subscribe(
86
100
  }
87
101
  )
88
102
  subscriptions_manager.force_lock! if ENV['FORCE_LOCK'] == 'true'
89
- subscriptions_manager.start
103
+ timeout = 20 # 20 seconds
104
+ deadline = Time.now + timeout
105
+ loop do
106
+ break if subscriptions_manager.start
107
+ if Time.now > deadline
108
+ puts "Failed to acquire subscriptions lock within #{timeout} seconds. Exiting now."
109
+ exit
110
+ end
111
+ sleep 2
112
+ end
90
113
 
91
114
  Kernel.trap('TERM') do
92
115
  puts "Received TERM signal. Stopping Subscriptions Manager and exiting..."
@@ -113,6 +113,10 @@ module PgEventstore
113
113
  lock_all
114
114
  @runners.each(&:start)
115
115
  @commands_handler.start
116
+ rescue PgEventstore::SubscriptionAlreadyLockedError
117
+ @subscriptions_set&.delete
118
+ @subscriptions_set = nil
119
+ raise
116
120
  end
117
121
 
118
122
  # @param error [StandardError]
@@ -30,7 +30,7 @@ module PgEventstore
30
30
  attr_reader :config
31
31
  private :config
32
32
 
33
- def_delegators :@subscription_feeder, :start, :stop, :force_lock!
33
+ def_delegators :@subscription_feeder, :stop, :force_lock!
34
34
 
35
35
  # @param config [PgEventstore::Config]
36
36
  # @param set_name [String]
@@ -94,6 +94,14 @@ module PgEventstore
94
94
  @subscription_feeder.read_only_subscriptions_set
95
95
  end
96
96
 
97
+ # @return [PgEventstore::BasicRunner, nil]
98
+ def start
99
+ @subscription_feeder.start
100
+ rescue PgEventstore::SubscriptionAlreadyLockedError => e
101
+ PgEventstore.logger&.warn(e.message)
102
+ nil
103
+ end
104
+
97
105
  private
98
106
 
99
107
  # @param middlewares [Array<Symbol>, nil]
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PgEventstore
4
4
  # @return [String]
5
- VERSION = "1.1.4"
5
+ VERSION = "1.1.5"
6
6
  end
@@ -54,6 +54,8 @@ module PgEventstore
54
54
  # _@param_ `middlewares`
55
55
  def select_middlewares: (?::Array[Symbol]? middlewares) -> ::Array[PgEventstore::Middleware]
56
56
 
57
+ def start: () -> PgEventstore::BasicRunner?
58
+
57
59
  # Returns the value of attribute config.
58
60
  attr_accessor config: PgEventstore::Config
59
61
  end
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.1.4
4
+ version: 1.1.5
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-07-24 00:00:00.000000000 Z
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg