pg_eventstore 1.12.0 → 1.13.1

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/lib/pg_eventstore/cli/commands/base_command.rb +2 -0
  4. data/lib/pg_eventstore/cli/commands/callback_handlers/start_cmd_handlers.rb +1 -0
  5. data/lib/pg_eventstore/cli/commands/help_command.rb +1 -0
  6. data/lib/pg_eventstore/cli/commands/start_subscriptions_command.rb +3 -1
  7. data/lib/pg_eventstore/cli/commands/stop_subscriptions_command.rb +1 -0
  8. data/lib/pg_eventstore/cli/exit_codes.rb +1 -0
  9. data/lib/pg_eventstore/cli/parser_options/base_options.rb +1 -0
  10. data/lib/pg_eventstore/cli/parser_options/default_options.rb +1 -0
  11. data/lib/pg_eventstore/cli/parser_options/metadata.rb +1 -0
  12. data/lib/pg_eventstore/cli/parser_options/subscription_options.rb +1 -0
  13. data/lib/pg_eventstore/cli/try_to_delete_subscriptions_set.rb +2 -1
  14. data/lib/pg_eventstore/cli/try_unlock_subscriptions_set.rb +1 -0
  15. data/lib/pg_eventstore/cli/wait_for_subscriptions_set_shutdown.rb +1 -0
  16. data/lib/pg_eventstore/connection.rb +8 -3
  17. data/lib/pg_eventstore/extensions/callback_handlers_extension.rb +1 -0
  18. data/lib/pg_eventstore/pg_connection.rb +1 -0
  19. data/lib/pg_eventstore/query_builders/events_filtering.rb +1 -1
  20. data/lib/pg_eventstore/query_builders/partitions_filtering.rb +1 -1
  21. data/lib/pg_eventstore/subscriptions/basic_runner.rb +122 -35
  22. data/lib/pg_eventstore/subscriptions/callback_handlers/commands_handler_handlers.rb +1 -14
  23. data/lib/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rb +4 -3
  24. data/lib/pg_eventstore/subscriptions/callback_handlers/subscription_feeder_handlers.rb +1 -14
  25. data/lib/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rb +1 -19
  26. data/lib/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rb +1 -0
  27. data/lib/pg_eventstore/subscriptions/command_handlers/subscription_runners_commands.rb +1 -0
  28. data/lib/pg_eventstore/subscriptions/commands_handler.rb +5 -8
  29. data/lib/pg_eventstore/subscriptions/events_processor.rb +7 -2
  30. data/lib/pg_eventstore/subscriptions/extensions/base_command_extension.rb +1 -0
  31. data/lib/pg_eventstore/subscriptions/extensions/command_class_lookup_extension.rb +1 -0
  32. data/lib/pg_eventstore/subscriptions/runner_recovery_strategies/restore_connection.rb +44 -0
  33. data/lib/pg_eventstore/subscriptions/runner_recovery_strategies/restore_subscription_feeder.rb +27 -0
  34. data/lib/pg_eventstore/subscriptions/runner_recovery_strategies/restore_subscription_runner.rb +34 -0
  35. data/lib/pg_eventstore/subscriptions/runner_recovery_strategies.rb +5 -0
  36. data/lib/pg_eventstore/subscriptions/runner_recovery_strategy.rb +21 -0
  37. data/lib/pg_eventstore/subscriptions/subscription_feeder.rb +18 -5
  38. data/lib/pg_eventstore/subscriptions/subscription_runner.rb +1 -13
  39. data/lib/pg_eventstore/subscriptions/subscriptions_lifecycle.rb +1 -0
  40. data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +20 -3
  41. data/lib/pg_eventstore/subscriptions/subscriptions_set_lifecycle.rb +1 -0
  42. data/lib/pg_eventstore/version.rb +1 -1
  43. data/lib/pg_eventstore/web/application.rb +1 -0
  44. data/lib/pg_eventstore.rb +2 -1
  45. data/sig/pg_eventstore/connection.rbs +2 -0
  46. data/sig/pg_eventstore/subscriptions/basic_runner.rbs +26 -10
  47. data/sig/pg_eventstore/subscriptions/callback_handlers/commands_handler_handlers.rbs +5 -5
  48. data/sig/pg_eventstore/subscriptions/callback_handlers/subscription_feeder_handlers.rbs +1 -3
  49. data/sig/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rbs +0 -4
  50. data/sig/pg_eventstore/subscriptions/commands_handler.rbs +8 -11
  51. data/sig/pg_eventstore/subscriptions/events_processor.rbs +5 -17
  52. data/sig/pg_eventstore/subscriptions/runner_recovery_strategies/restore_connection.rbs +18 -0
  53. data/sig/pg_eventstore/subscriptions/runner_recovery_strategies/restore_subscription_feeder.rbs +11 -0
  54. data/sig/pg_eventstore/subscriptions/runner_recovery_strategies/restore_subscription_runner.rbs +17 -0
  55. data/sig/pg_eventstore/subscriptions/runner_recovery_strategy.rbs +7 -0
  56. data/sig/pg_eventstore/subscriptions/subscription_feeder.rbs +6 -8
  57. data/sig/pg_eventstore/subscriptions/subscription_runner.rbs +6 -35
  58. data/sig/pg_eventstore/subscriptions/subscriptions_manager.rbs +8 -0
  59. metadata +11 -2
@@ -2,6 +2,7 @@
2
2
 
3
3
  module PgEventstore
4
4
  module Extensions
5
+ # @!visibility private
5
6
  module CommandClassLookupExtension
6
7
  # @param cmd_name [String, Symbol]
7
8
  # @return [Class]
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEventstore
4
+ module RunnerRecoveryStrategies
5
+ # @!visibility private
6
+ class RestoreConnection
7
+ # @return [Integer] seconds
8
+ TIME_BETWEEN_RETRIES = 5
9
+ # @return [Array<StandardError>]
10
+ EXCEPTIONS_TO_HANDLE = [PG::ConnectionBad, PG::UnableToSend, ConnectionPool::TimeoutError].freeze
11
+
12
+ include RunnerRecoveryStrategy
13
+
14
+ # @param config_name [Symbol]
15
+ def initialize(config_name)
16
+ @config_name = config_name
17
+ end
18
+
19
+ def recovers?(error)
20
+ EXCEPTIONS_TO_HANDLE.any? {error.is_a?(_1) }
21
+ end
22
+
23
+ def recover(_error)
24
+ loop do
25
+ sleep TIME_BETWEEN_RETRIES
26
+
27
+ connection.with do |conn|
28
+ conn.exec('select version()')
29
+ # No error was raised during the request. We are good to recover!
30
+ return true
31
+ end
32
+ rescue *EXCEPTIONS_TO_HANDLE
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # @return [PgEventstore::Connection]
39
+ def connection
40
+ PgEventstore.connection(@config_name)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEventstore
4
+ module RunnerRecoveryStrategies
5
+ # @!visibility private
6
+ class RestoreSubscriptionFeeder
7
+ include RunnerRecoveryStrategy
8
+
9
+ # @param subscriptions_set_lifecycle [PgEventstore::SubscriptionsSetLifecycle]
10
+ def initialize(subscriptions_set_lifecycle:)
11
+ @subscriptions_set_lifecycle = subscriptions_set_lifecycle
12
+ end
13
+
14
+ def recovers?(_error)
15
+ true
16
+ end
17
+
18
+ def recover(_error)
19
+ subscriptions_set = @subscriptions_set_lifecycle.persisted_subscriptions_set
20
+ return false if subscriptions_set.restart_count >= subscriptions_set.max_restarts_number
21
+
22
+ sleep subscriptions_set.time_between_restarts
23
+ true
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEventstore
4
+ module RunnerRecoveryStrategies
5
+ # @!visibility private
6
+ class RestoreSubscriptionRunner
7
+ include RunnerRecoveryStrategy
8
+
9
+ # @param subscription [PgEventstore::Subscription]
10
+ # @param restart_terminator [#call, nil]
11
+ # @param failed_subscription_notifier [#call, nil]
12
+ def initialize(subscription:, restart_terminator:, failed_subscription_notifier:)
13
+ @subscription = subscription
14
+ @restart_terminator = restart_terminator
15
+ @failed_subscription_notifier = failed_subscription_notifier
16
+ end
17
+
18
+ def recovers?(error)
19
+ error.is_a?(WrappedException)
20
+ end
21
+
22
+ def recover(error)
23
+ return false if @restart_terminator&.call(@subscription.dup)
24
+ if @subscription.restart_count >= @subscription.max_restarts_number
25
+ @failed_subscription_notifier&.call(@subscription.dup, Utils.unwrap_exception(error))
26
+ return false
27
+ end
28
+
29
+ sleep @subscription.time_between_restarts
30
+ true
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'runner_recovery_strategies/restore_connection'
4
+ require_relative 'runner_recovery_strategies/restore_subscription_runner'
5
+ require_relative 'runner_recovery_strategies/restore_subscription_feeder'
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEventstore
4
+ # Defines an interface of a recovery strategy of the BasicRunner.
5
+ # See {PgEventstore::BasicRunner} for an example of usage.
6
+ module RunnerRecoveryStrategy
7
+ # Determines whether this strategy can recover from the error. If multiple strategies can recover from the error,
8
+ # the first one from the :recovery_strategies array is selected.
9
+ # @param error [StandardError]
10
+ # @return [Boolean]
11
+ def recovers?(error)
12
+ end
13
+
14
+ # Actual implementation of recovery strategy. Usually you want to implement here a logic that restores from the
15
+ # error. The returned boolean value will be used to determine whether the runner should be restarted.
16
+ # @param error [StandardError]
17
+ # @return [Boolean]
18
+ def recover(error)
19
+ end
20
+ end
21
+ end
@@ -3,6 +3,7 @@
3
3
  module PgEventstore
4
4
  # This class is responsible for starting/stopping all SubscriptionRunners. The background runner of it is responsible
5
5
  # for events pulling and feeding those SubscriptionRunners.
6
+ # @!visibility private
6
7
  class SubscriptionFeeder
7
8
  extend Forwardable
8
9
 
@@ -15,7 +16,11 @@ module PgEventstore
15
16
  # @param subscriptions_lifecycle [PgEventstore::SubscriptionsLifecycle]
16
17
  def initialize(config_name:, subscriptions_set_lifecycle:, subscriptions_lifecycle:)
17
18
  @config_name = config_name
18
- @basic_runner = BasicRunner.new(0.2, 0)
19
+ @basic_runner = BasicRunner.new(
20
+ run_interval: 0.2,
21
+ async_shutdown_time: 0,
22
+ recovery_strategies: recovery_strategies(config_name, subscriptions_set_lifecycle)
23
+ )
19
24
  @subscriptions_set_lifecycle = subscriptions_set_lifecycle
20
25
  @subscriptions_lifecycle = subscriptions_lifecycle
21
26
  @commands_handler = CommandsHandler.new(@config_name, self, @subscriptions_lifecycle.runners)
@@ -71,10 +76,6 @@ module PgEventstore
71
76
  :after_runner_died, :before,
72
77
  SubscriptionFeederHandlers.setup_handler(:persist_error_info, @subscriptions_set_lifecycle)
73
78
  )
74
- @basic_runner.define_callback(
75
- :after_runner_died, :before,
76
- SubscriptionFeederHandlers.setup_handler(:restart_runner, @subscriptions_set_lifecycle, @basic_runner)
77
- )
78
79
 
79
80
  @basic_runner.define_callback(
80
81
  :process_async, :before,
@@ -107,5 +108,17 @@ module PgEventstore
107
108
  SubscriptionFeederHandlers.setup_handler(:update_subscriptions_set_restarts, @subscriptions_set_lifecycle)
108
109
  )
109
110
  end
111
+
112
+ # @param config_name [Symbol]
113
+ # @param subscriptions_set_lifecycle [PgEventstore::SubscriptionsSetLifecycle]
114
+ # @return [Array<PgEventstore::RunnerRecoveryStrategy>]
115
+ def recovery_strategies(config_name, subscriptions_set_lifecycle)
116
+ [
117
+ RunnerRecoveryStrategies::RestoreConnection.new(config_name),
118
+ RunnerRecoveryStrategies::RestoreSubscriptionFeeder.new(
119
+ subscriptions_set_lifecycle: subscriptions_set_lifecycle
120
+ ),
121
+ ]
122
+ end
110
123
  end
111
124
  end
@@ -28,15 +28,10 @@ module PgEventstore
28
28
  # @param stats [PgEventstore::SubscriptionHandlerPerformance]
29
29
  # @param events_processor [PgEventstore::EventsProcessor]
30
30
  # @param subscription [PgEventstore::Subscription]
31
- # @param restart_terminator [#call, nil]
32
- # @param failed_subscription_notifier [#call, nil]
33
- def initialize(stats:, events_processor:, subscription:, restart_terminator: nil,
34
- failed_subscription_notifier: nil)
31
+ def initialize(stats:, events_processor:, subscription:)
35
32
  @stats = stats
36
33
  @events_processor = events_processor
37
34
  @subscription = subscription
38
- @restart_terminator = restart_terminator
39
- @failed_subscription_notifier = failed_subscription_notifier
40
35
 
41
36
  attach_callbacks
42
37
  end
@@ -87,13 +82,6 @@ module PgEventstore
87
82
  :error, :after,
88
83
  SubscriptionRunnerHandlers.setup_handler(:update_subscription_error, @subscription)
89
84
  )
90
- @events_processor.define_callback(
91
- :error, :after,
92
- SubscriptionRunnerHandlers.setup_handler(
93
- :restart_events_processor,
94
- @subscription, @restart_terminator, @failed_subscription_notifier, @events_processor
95
- )
96
- )
97
85
 
98
86
  @events_processor.define_callback(
99
87
  :feed, :after,
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEventstore
4
+ # @!visibility private
4
5
  class SubscriptionsLifecycle
5
6
  extend Forwardable
6
7
 
@@ -3,6 +3,8 @@
3
3
  require 'forwardable'
4
4
  require_relative 'runner_state'
5
5
  require_relative 'basic_runner'
6
+ require_relative 'runner_recovery_strategy'
7
+ require_relative 'runner_recovery_strategies'
6
8
  require_relative 'subscription'
7
9
  require_relative 'events_processor'
8
10
  require_relative 'subscription_handler_performance'
@@ -102,11 +104,11 @@ module PgEventstore
102
104
  runner = SubscriptionRunner.new(
103
105
  stats: SubscriptionHandlerPerformance.new,
104
106
  events_processor: EventsProcessor.new(
105
- create_raw_event_handler(middlewares, handler), graceful_shutdown_timeout: graceful_shutdown_timeout
107
+ create_raw_event_handler(middlewares, handler),
108
+ graceful_shutdown_timeout: graceful_shutdown_timeout,
109
+ recovery_strategies: recovery_strategies(subscription, restart_terminator, failed_subscription_notifier)
106
110
  ),
107
111
  subscription: subscription,
108
- restart_terminator: restart_terminator,
109
- failed_subscription_notifier: failed_subscription_notifier
110
112
  )
111
113
 
112
114
  @subscriptions_lifecycle.runners.push(runner)
@@ -170,5 +172,20 @@ module PgEventstore
170
172
 
171
173
  config.middlewares.slice(*middlewares).values
172
174
  end
175
+
176
+ # @param subscription [PgEventstore::Subscription]
177
+ # @param restart_terminator [#call, nil]
178
+ # @param failed_subscription_notifier [#call, nil]
179
+ # @return [Array<PgEventstore::RunnerRecoveryStrategy>]
180
+ def recovery_strategies(subscription, restart_terminator, failed_subscription_notifier)
181
+ [
182
+ RunnerRecoveryStrategies::RestoreConnection.new(config_name),
183
+ RunnerRecoveryStrategies::RestoreSubscriptionRunner.new(
184
+ subscription: subscription,
185
+ restart_terminator: restart_terminator,
186
+ failed_subscription_notifier: failed_subscription_notifier,
187
+ ),
188
+ ]
189
+ end
173
190
  end
174
191
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEventstore
4
+ # @!visibility private
4
5
  class SubscriptionsSetLifecycle
5
6
  # @return [Integer] number of seconds between heartbeat updates
6
7
  HEARTBEAT_INTERVAL = 10 # seconds
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PgEventstore
4
4
  # @return [String]
5
- VERSION = "1.12.0"
5
+ VERSION = "1.13.1"
6
6
  end
@@ -5,6 +5,7 @@ require 'base64'
5
5
 
6
6
  module PgEventstore
7
7
  module Web
8
+ # @!visibility private
8
9
  class Application < Sinatra::Base
9
10
  # @return [Symbol]
10
11
  DEFAULT_ADMIN_UI_CONFIG = :admin_web_ui
data/lib/pg_eventstore.rb CHANGED
@@ -36,10 +36,11 @@ module PgEventstore
36
36
  # @return [Object] a result of the given block
37
37
  def configure(name: DEFAULT_CONFIG)
38
38
  mutex.synchronize do
39
- @config[name] ||= Config.new(name: name)
39
+ @config[name] = @config[name] ? Config.new(name: name, **@config[name].options_hash) : Config.new(name: name)
40
40
  connection_config_was = @config[name].connection_options
41
41
 
42
42
  yield(@config[name]).tap do
43
+ @config[name].freeze
43
44
  next if connection_config_was == @config[name].connection_options
44
45
 
45
46
  # Reset the connection if user decided to reconfigure connection's options
@@ -12,6 +12,8 @@ module PgEventstore
12
12
  # _@param_ `pool_timeout` — Connection pool timeout in seconds
13
13
  def initialize: (uri: String, ?pool_size: Integer, ?pool_timeout: Integer) -> void
14
14
 
15
+ def shutdown: -> untyped
16
+
15
17
  def with: () { (PG::Connection connection) -> untyped } -> untyped
16
18
 
17
19
  def init_pool: () -> ConnectionPool[untyped]
@@ -1,12 +1,25 @@
1
1
  module PgEventstore
2
2
  class BasicRunner
3
- include PgEventstore::Extensions::CallbacksExtension
3
+ include Extensions::CallbacksExtension
4
4
  extend Forwardable
5
5
 
6
- # _@param_ `run_interval` seconds. Determines how often to run async task. Async task is determined by :after_runner_stopped callback
7
- #
8
- # _@param_ `async_shutdown_time` — seconds. Determines how long to wait for the async shutdown to wait for the runner to finish.
9
- %a{rbs:test:skip} def initialize: ((Integer | Float) run_interval, (Integer | Float) async_shutdown_time) -> void
6
+ @async_shutdown_time: Integer | Float
7
+ @mutex: Thread::Mutex
8
+ @recovery_strategies: Array[RunnerRecoveryStrategy]
9
+ @run_interval: Integer | Float
10
+ @runner: Thread?
11
+
12
+ @state: RunnerState
13
+
14
+ %a{rbs:test:skip} def initialize: (
15
+ run_interval: (Integer | Float),
16
+ async_shutdown_time: (Integer | Float),
17
+ recovery_strategies: Array[RunnerRecoveryStrategy]
18
+ ) -> void
19
+
20
+ def async_recover: (StandardError error, RunnerRecoveryStrategy strategy, Integer current_runner_id)-> Thread
21
+
22
+ def restore: -> untyped
10
23
 
11
24
  def start: () -> self
12
25
 
@@ -14,14 +27,16 @@ module PgEventstore
14
27
 
15
28
  def stop_async: () -> self
16
29
 
17
- def restore: () -> self
18
-
19
30
  def wait_for_finish: () -> self
20
31
 
21
32
  def state: () -> String
22
33
 
23
34
  # _@param_ `state`
24
- def within_state: (Symbol state) { () -> untyped } -> untyped
35
+ def within_state: (Symbol state) { () -> untyped } -> untyped?
36
+
37
+ private
38
+
39
+ def suitable_strategy: (StandardError error)-> RunnerRecoveryStrategy?
25
40
 
26
41
  def synchronize: () { () -> untyped } -> untyped
27
42
 
@@ -29,9 +44,10 @@ module PgEventstore
29
44
 
30
45
  def delegate_change_state_cbx: () -> void
31
46
 
32
- # _@param_ `state`
33
47
  def change_state: (String state) -> void
34
48
 
35
- def define_callback: () -> void
49
+ def recoverable: { () -> untyped } -> untyped
50
+
51
+ def init_recovery_ripper: (Integer current_runner_id) -> untyped
36
52
  end
37
53
  end
@@ -1,10 +1,10 @@
1
1
  module PgEventstore
2
2
  class CommandsHandlerHandlers
3
- def self.process_feeder_commands: (Symbol config_name, PgEventstore::SubscriptionFeeder subscription_feeder) -> void
3
+ def self.process_feeder_commands: (Symbol config_name, SubscriptionFeeder subscription_feeder) -> void
4
4
 
5
- def self.process_runners_commands: (Symbol config_name, Array[PgEventstore::SubscriptionRunner] runners,
6
- PgEventstore::SubscriptionFeeder subscription_feeder) -> void
7
-
8
- def self.restore_runner: (PgEventstore::BasicRunner basic_runner, Integer restart_delay, StandardError error) -> void
5
+ def self.process_runners_commands: (
6
+ Symbol config_name, Array[SubscriptionRunner] runners,
7
+ SubscriptionFeeder subscription_feeder
8
+ ) -> void
9
9
  end
10
10
  end
@@ -1,6 +1,6 @@
1
1
  module PgEventstore
2
2
  class SubscriptionFeederHandlers
3
- include PgEventstore::Extensions::CallbackHandlersExtension
3
+ include Extensions::CallbackHandlersExtension
4
4
 
5
5
  def self.update_subscriptions_set_state: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle, String state) -> void
6
6
 
@@ -12,8 +12,6 @@ module PgEventstore
12
12
 
13
13
  def self.persist_error_info: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle, StandardError error) -> void
14
14
 
15
- def self.restart_runner: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle, PgEventstore::BasicRunner basic_runner, StandardError _error) -> void
16
-
17
15
  def self.ping_subscriptions_set: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle) -> void
18
16
 
19
17
  def self.feed_runners: (PgEventstore::SubscriptionsLifecycle subscriptions_lifecycle, Symbol config_name) -> void
@@ -6,10 +6,6 @@ module PgEventstore
6
6
 
7
7
  def self.update_subscription_error: (PgEventstore::Subscription subscription, PgEventstore::WrappedException error) -> void
8
8
 
9
- def self.restart_events_processor: (PgEventstore::Subscription subscription, _RestartTerminator? restart_terminator,
10
- _FailedSubscriptionNotifier? failed_subscription_notifier, PgEventstore::EventsProcessor events_processor,
11
- PgEventstore::WrappedException error) -> void
12
-
13
9
  def self.update_subscription_chunk_stats: (PgEventstore::Subscription subscription, Integer global_position) -> void
14
10
 
15
11
  def self.update_subscription_restarts: (PgEventstore::Subscription subscription) -> void
@@ -1,25 +1,22 @@
1
1
  module PgEventstore
2
2
  class CommandsHandler
3
3
  extend Forwardable
4
- RESTART_DELAY: Integer
4
+
5
5
  PULL_INTERVAL: Integer
6
6
 
7
+ @basic_runner: BasicRunner
8
+ @config_name: Symbol
9
+
10
+ @runners: ::Array[SubscriptionRunner]
11
+ @subscription_feeder: SubscriptionFeeder
12
+
7
13
  # _@param_ `config_name`
8
14
  #
9
15
  # _@param_ `subscription_feeder`
10
16
  #
11
17
  # _@param_ `runners`
12
- def initialize: (Symbol config_name, PgEventstore::SubscriptionFeeder subscription_feeder, ::Array[PgEventstore::SubscriptionRunner] runners) -> void
18
+ def initialize: (Symbol config_name, SubscriptionFeeder subscription_feeder, ::Array[SubscriptionRunner] runners) -> void
13
19
 
14
20
  def attach_runner_callbacks: () -> untyped
15
-
16
- def process_async: () -> untyped
17
-
18
- # _@param_ `error`
19
- def after_runner_died: (StandardError error) -> void
20
-
21
- def subscription_feeder_commands: () -> PgEventstore::CommandHandlers::SubscriptionFeederCommands
22
-
23
- def subscription_runners_commands: () -> PgEventstore::CommandHandlers::SubscriptionRunnersCommands
24
21
  end
25
22
  end
@@ -3,32 +3,20 @@ module PgEventstore
3
3
  include PgEventstore::Extensions::CallbacksExtension
4
4
  extend Forwardable
5
5
 
6
- # _@param_ `handler`
7
- %a{rbs:test:skip} def initialize: (_RawEventHandler handler, graceful_shutdown_timeout: Float | Integer) -> void
6
+ %a{rbs:test:skip} def initialize: (
7
+ _RawEventHandler handler,
8
+ graceful_shutdown_timeout: Float | Integer,
9
+ ?recovery_strategies: Array[RunnerRecoveryStrategy]
10
+ ) -> void
8
11
 
9
- # _@param_ `raw_events`
10
12
  def feed: (::Array[::Hash[untyped, untyped]] raw_events) -> void
11
13
 
12
14
  def events_left_in_chunk: () -> Integer
13
15
 
14
16
  def clear_chunk: () -> void
15
17
 
16
- # _@param_ `raw_event`
17
18
  def process_event: (::Hash[untyped, untyped] raw_event) -> void
18
19
 
19
20
  def attach_runner_callbacks: () -> void
20
-
21
- def process_async: () -> void
22
-
23
- def after_runner_died: (StandardError error) -> void
24
-
25
- def before_runner_restored: () -> void
26
-
27
- def change_state: (*untyped args, **untyped kwargs) -> void
28
-
29
- # _@param_ `raw_event`
30
- def global_position: (::Hash[untyped, untyped] raw_event) -> Integer
31
-
32
- def define_callback: () -> void
33
21
  end
34
22
  end
@@ -0,0 +1,18 @@
1
+ module PgEventstore
2
+ module RunnerRecoveryStrategies
3
+ class RestoreConnection
4
+ include RunnerRecoveryStrategy
5
+
6
+ EXCEPTIONS_TO_HANDLE: Array[StandardError]
7
+ TIME_BETWEEN_RETRIES: Integer
8
+
9
+ @config_name: Symbol
10
+
11
+ def initialize: (Symbol config_name)-> untyped
12
+
13
+ private
14
+
15
+ def connection: -> Connection
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module PgEventstore
2
+ module RunnerRecoveryStrategies
3
+ class RestoreSubscriptionFeeder
4
+ include RunnerRecoveryStrategy
5
+
6
+ @subscriptions_set_lifecycle: SubscriptionsSetLifecycle
7
+
8
+ def initialize: (subscriptions_set_lifecycle: SubscriptionsSetLifecycle)-> untyped
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module PgEventstore
2
+ module RunnerRecoveryStrategies
3
+ class RestoreSubscriptionRunner
4
+ include RunnerRecoveryStrategy
5
+
6
+ @failed_subscription_notifier: _FailedSubscriptionNotifier?
7
+ @restart_terminator: _RestartTerminator?
8
+ @subscription: Subscription
9
+
10
+ def initialize: (
11
+ subscription: Subscription,
12
+ restart_terminator: _RestartTerminator?,
13
+ failed_subscription_notifier: _FailedSubscriptionNotifier?
14
+ )-> untyped
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module PgEventstore
2
+ module RunnerRecoveryStrategy
3
+ def recover: (StandardError error)-> bool
4
+
5
+ def recovers?: (StandardError error)-> bool
6
+ end
7
+ end
@@ -17,19 +17,17 @@ module PgEventstore
17
17
 
18
18
  def id: () -> Integer?
19
19
 
20
- # _@param_ `runner`
21
- def add: (PgEventstore::SubscriptionRunner runner) -> PgEventstore::SubscriptionRunner
22
-
23
20
  def start_all: () -> void
24
21
 
25
22
  def stop_all: () -> void
26
23
 
27
- def read_only_subscriptions: () -> ::Array[PgEventstore::Subscription]
28
-
29
- def read_only_subscriptions_set: () -> PgEventstore::SubscriptionsSet?
30
-
31
24
  def attach_runner_callbacks: () -> void
32
25
 
33
- def assert_proper_state!: () -> void
26
+ private
27
+
28
+ def recovery_strategies: (
29
+ Symbol config_name,
30
+ SubscriptionsSetLifecycle subscriptions_set_lifecycle
31
+ ) -> Array[RunnerRecoveryStrategy]
34
32
  end
35
33
  end
@@ -5,19 +5,13 @@ module PgEventstore
5
5
  MIN_EVENTS_PER_CHUNK: Integer
6
6
  INITIAL_EVENTS_PER_CHUNK: Integer
7
7
 
8
- # _@param_ `stats`
9
- #
10
- # _@param_ `events_processor`
11
- #
12
- # _@param_ `subscription`
13
- #
14
- # _@param_ `restart_terminator`
15
- #
16
- # _@param_ `failed_subscription_notifier`
8
+ # Returns the value of attribute subscription.
9
+ attr_reader subscription: Subscription
10
+
17
11
  def initialize: (
18
- stats: PgEventstore::SubscriptionHandlerPerformance,
19
- events_processor: PgEventstore::EventsProcessor,
20
- subscription: PgEventstore::Subscription,
12
+ stats: SubscriptionHandlerPerformance,
13
+ events_processor: EventsProcessor,
14
+ subscription: Subscription,
21
15
  ?restart_terminator: _RestartTerminator?,
22
16
  ?failed_subscription_notifier: _FailedSubscriptionNotifier?
23
17
  ) -> void
@@ -31,28 +25,5 @@ module PgEventstore
31
25
  def estimate_events_number: () -> Integer
32
26
 
33
27
  def attach_callbacks: () -> void
34
-
35
- # _@param_ `action`
36
- def track_exec_time: (Proc action, *untyped args) -> void
37
-
38
- # _@param_ `current_position`
39
- def update_subscription_stats: (Integer current_position) -> void
40
-
41
- # _@param_ `state`
42
- def update_subscription_state: (String state) -> void
43
-
44
- def update_subscription_restarts: () -> void
45
-
46
- # _@param_ `error`
47
- def update_subscription_error: (StandardError error) -> void
48
-
49
- # _@param_ `global_position`
50
- def update_subscription_chunk_stats: (Integer global_position) -> void
51
-
52
- # _@param_ `_error`
53
- def restart_subscription: (StandardError error) -> void
54
-
55
- # Returns the value of attribute subscription.
56
- attr_accessor subscription: PgEventstore::Subscription
57
28
  end
58
29
  end
@@ -74,5 +74,13 @@ module PgEventstore
74
74
 
75
75
  # Returns the value of attribute config.
76
76
  attr_accessor config: PgEventstore::Config
77
+
78
+ private
79
+
80
+ def recovery_strategies: (
81
+ Subscription subscription,
82
+ _RestartTerminator? restart_terminator,
83
+ _FailedSubscriptionNotifier? failed_subscription_notifier
84
+ ) -> Array[RunnerRecoveryStrategy]
77
85
  end
78
86
  end