pg_eventstore 1.1.3 → 1.1.4

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/README.md +4 -3
  4. data/lib/pg_eventstore/abstract_command.rb +2 -0
  5. data/lib/pg_eventstore/callbacks.rb +3 -0
  6. data/lib/pg_eventstore/client.rb +6 -1
  7. data/lib/pg_eventstore/config.rb +1 -1
  8. data/lib/pg_eventstore/connection.rb +9 -1
  9. data/lib/pg_eventstore/errors.rb +45 -26
  10. data/lib/pg_eventstore/event.rb +2 -1
  11. data/lib/pg_eventstore/event_class_resolver.rb +1 -1
  12. data/lib/pg_eventstore/event_deserializer.rb +8 -2
  13. data/lib/pg_eventstore/event_serializer.rb +2 -0
  14. data/lib/pg_eventstore/extensions/callbacks_extension.rb +1 -0
  15. data/lib/pg_eventstore/extensions/options_extension.rb +3 -1
  16. data/lib/pg_eventstore/queries/event_queries.rb +12 -4
  17. data/lib/pg_eventstore/queries/links_resolver.rb +3 -0
  18. data/lib/pg_eventstore/queries/partition_queries.rb +6 -0
  19. data/lib/pg_eventstore/queries/transaction_queries.rb +4 -0
  20. data/lib/pg_eventstore/queries.rb +1 -1
  21. data/lib/pg_eventstore/query_builders/{events_filtering_query.rb → events_filtering.rb} +3 -0
  22. data/lib/pg_eventstore/sql_builder.rb +18 -10
  23. data/lib/pg_eventstore/stream.rb +13 -2
  24. data/lib/pg_eventstore/subscriptions/basic_runner.rb +2 -0
  25. data/lib/pg_eventstore/subscriptions/commands_handler.rb +5 -3
  26. data/lib/pg_eventstore/subscriptions/queries/subscription_command_queries.rb +6 -4
  27. data/lib/pg_eventstore/subscriptions/queries/subscription_queries.rb +4 -2
  28. data/lib/pg_eventstore/subscriptions/queries/subscriptions_set_command_queries.rb +6 -4
  29. data/lib/pg_eventstore/subscriptions/queries/subscriptions_set_queries.rb +3 -0
  30. data/lib/pg_eventstore/subscriptions/runner_state.rb +1 -0
  31. data/lib/pg_eventstore/subscriptions/subscription.rb +19 -17
  32. data/lib/pg_eventstore/subscriptions/subscription_feeder.rb +4 -0
  33. data/lib/pg_eventstore/subscriptions/subscription_feeder_commands/base.rb +4 -4
  34. data/lib/pg_eventstore/subscriptions/subscription_handler_performance.rb +2 -1
  35. data/lib/pg_eventstore/subscriptions/subscription_runner.rb +5 -0
  36. data/lib/pg_eventstore/subscriptions/subscription_runner_commands/base.rb +4 -4
  37. data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +6 -4
  38. data/lib/pg_eventstore/subscriptions/subscriptions_set.rb +10 -10
  39. data/lib/pg_eventstore/version.rb +2 -1
  40. data/lib/pg_eventstore/web/application.rb +6 -6
  41. data/lib/pg_eventstore/web/paginator/base_collection.rb +15 -1
  42. data/lib/pg_eventstore/web/paginator/event_types_collection.rb +2 -1
  43. data/lib/pg_eventstore/web/paginator/events_collection.rb +7 -4
  44. data/lib/pg_eventstore/web/paginator/helpers.rb +3 -3
  45. data/lib/pg_eventstore/web/paginator/stream_contexts_collection.rb +2 -1
  46. data/lib/pg_eventstore/web/paginator/stream_ids_collection.rb +2 -1
  47. data/lib/pg_eventstore/web/paginator/stream_names_collection.rb +2 -1
  48. data/lib/pg_eventstore/web/subscriptions/set_collection.rb +2 -0
  49. data/lib/pg_eventstore/web/subscriptions/subscriptions.rb +2 -0
  50. data/lib/pg_eventstore/web/subscriptions/subscriptions_set.rb +2 -0
  51. data/lib/pg_eventstore/web/subscriptions/subscriptions_to_set_association.rb +6 -1
  52. data/lib/pg_eventstore.rb +6 -1
  53. data/rbs_collection.lock.yaml +16 -0
  54. data/rbs_collection.yaml +23 -0
  55. data/sig/interfaces/callback.rbs +3 -0
  56. data/sig/interfaces/event_class_resolver.rbs +3 -0
  57. data/sig/interfaces/event_modifier.rbs +3 -0
  58. data/sig/interfaces/restart_terminator.rbs +3 -0
  59. data/sig/interfaces/subscription_handler.rbs +3 -0
  60. data/sig/pg/basic_type_registry.rbs +21 -0
  61. data/sig/pg/connection.rbs +407 -0
  62. data/sig/pg/constants.rbs +153 -0
  63. data/sig/pg_eventstore/abstract_command.rbs +11 -0
  64. data/sig/pg_eventstore/callbacks.rbs +21 -0
  65. data/sig/pg_eventstore/client.rbs +67 -0
  66. data/sig/pg_eventstore/commands/append.rbs +33 -0
  67. data/sig/pg_eventstore/commands/event_modifiers/prepare_link_event.rbs +24 -0
  68. data/sig/pg_eventstore/commands/event_modifiers/prepare_regular_event.rbs +12 -0
  69. data/sig/pg_eventstore/commands/link_to.rbs +17 -0
  70. data/sig/pg_eventstore/commands/multiple.rbs +7 -0
  71. data/sig/pg_eventstore/commands/read.rbs +10 -0
  72. data/sig/pg_eventstore/commands/regular_stream_read_paginated.rbs +32 -0
  73. data/sig/pg_eventstore/commands/system_stream_read_paginated.rbs +30 -0
  74. data/sig/pg_eventstore/config.rbs +51 -0
  75. data/sig/pg_eventstore/connection.rbs +30 -0
  76. data/sig/pg_eventstore/errors.rbs +116 -0
  77. data/sig/pg_eventstore/event.rbs +46 -0
  78. data/sig/pg_eventstore/event_class_resolver.rbs +6 -0
  79. data/sig/pg_eventstore/event_deserializer.rbs +20 -0
  80. data/sig/pg_eventstore/event_serializer.rbs +13 -0
  81. data/sig/pg_eventstore/extensions/callbacks_extension.rbs +23 -0
  82. data/sig/pg_eventstore/extensions/options_extension.rbs +37 -0
  83. data/sig/pg_eventstore/extensions/using_connection_extension.rbs +14 -0
  84. data/sig/pg_eventstore/middleware.rbs +9 -0
  85. data/sig/pg_eventstore/pg_connection.rbs +13 -0
  86. data/sig/pg_eventstore/queries/event_queries.rbs +50 -0
  87. data/sig/pg_eventstore/queries/links_resolver.rbs +19 -0
  88. data/sig/pg_eventstore/queries/partition_queries.rbs +74 -0
  89. data/sig/pg_eventstore/queries/transaction_queries.rbs +21 -0
  90. data/sig/pg_eventstore/queries.rbs +23 -0
  91. data/sig/pg_eventstore/query_builders/events_filtering_query.rbs +62 -0
  92. data/sig/pg_eventstore/sql_builder.rbs +74 -0
  93. data/sig/pg_eventstore/stream.rbs +40 -0
  94. data/sig/pg_eventstore/subscriptions/basic_runner.rbs +37 -0
  95. data/sig/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rbs +16 -0
  96. data/sig/pg_eventstore/subscriptions/command_handlers/subscription_runners_commands.rbs +18 -0
  97. data/sig/pg_eventstore/subscriptions/commands_handler.rbs +25 -0
  98. data/sig/pg_eventstore/subscriptions/events_processor.rbs +34 -0
  99. data/sig/pg_eventstore/subscriptions/extensions/base_command_extension.rbs +20 -0
  100. data/sig/pg_eventstore/subscriptions/extensions/command_class_lookup_extension.rbs +8 -0
  101. data/sig/pg_eventstore/subscriptions/queries/subscription_command_queries.rbs +56 -0
  102. data/sig/pg_eventstore/subscriptions/queries/subscription_queries.rbs +73 -0
  103. data/sig/pg_eventstore/subscriptions/queries/subscriptions_set_command_queries.rbs +39 -0
  104. data/sig/pg_eventstore/subscriptions/queries/subscriptions_set_queries.rbs +36 -0
  105. data/sig/pg_eventstore/subscriptions/runner_state.rbs +16 -0
  106. data/sig/pg_eventstore/subscriptions/subscription.rbs +96 -0
  107. data/sig/pg_eventstore/subscriptions/subscription_feeder.rbs +64 -0
  108. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/base.rbs +45 -0
  109. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/restore.rbs +8 -0
  110. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/start_all.rbs +8 -0
  111. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/stop.rbs +8 -0
  112. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/stop_all.rbs +8 -0
  113. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands.rbs +8 -0
  114. data/sig/pg_eventstore/subscriptions/subscription_handler_performance.rbs +12 -0
  115. data/sig/pg_eventstore/subscriptions/subscription_runner.rbs +55 -0
  116. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/base.rbs +47 -0
  117. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/reset_position.rbs +11 -0
  118. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/restore.rbs +8 -0
  119. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/start.rbs +8 -0
  120. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/stop.rbs +8 -0
  121. data/sig/pg_eventstore/subscriptions/subscription_runner_commands.rbs +8 -0
  122. data/sig/pg_eventstore/subscriptions/subscription_runners_feeder.rbs +13 -0
  123. data/sig/pg_eventstore/subscriptions/subscriptions_manager.rbs +60 -0
  124. data/sig/pg_eventstore/subscriptions/subscriptions_set.rbs +72 -0
  125. data/sig/pg_eventstore/utils.rbs +20 -0
  126. data/sig/pg_eventstore/version.rbs +3 -0
  127. data/sig/pg_eventstore/web/paginator/base_collection.rbs +51 -0
  128. data/sig/pg_eventstore/web/paginator/event_types_collection.rbs +15 -0
  129. data/sig/pg_eventstore/web/paginator/events_collection.rbs +31 -0
  130. data/sig/pg_eventstore/web/paginator/helpers.rbs +38 -0
  131. data/sig/pg_eventstore/web/paginator/stream_contexts_collection.rbs +15 -0
  132. data/sig/pg_eventstore/web/paginator/stream_ids_collection.rbs +15 -0
  133. data/sig/pg_eventstore/web/paginator/stream_names_collection.rbs +15 -0
  134. data/sig/pg_eventstore/web/subscriptions/helpers.rbs +48 -0
  135. data/sig/pg_eventstore/web/subscriptions/set_collection.rbs +18 -0
  136. data/sig/pg_eventstore/web/subscriptions/subscriptions.rbs +18 -0
  137. data/sig/pg_eventstore/web/subscriptions/subscriptions_set.rbs +18 -0
  138. data/sig/pg_eventstore/web/subscriptions/subscriptions_to_set_association.rbs +18 -0
  139. data/sig/pg_eventstore.rbs +42 -0
  140. metadata +90 -3
@@ -10,13 +10,15 @@ module PgEventstore
10
10
  class CommandsHandler
11
11
  extend Forwardable
12
12
 
13
- RESTART_DELAY = 5 # seconds
14
- PULL_INTERVAL = 1 # seconds
13
+ # @return [Integer] the delay in seconds between runner restarts
14
+ RESTART_DELAY = 5
15
+ # @return [Integer] seconds, how often to check for new commands
16
+ PULL_INTERVAL = 1
15
17
 
16
18
  def_delegators :@basic_runner, :start, :stop, :state, :stop_async, :wait_for_finish
17
19
 
18
20
  # @param config_name [Symbol]
19
- # @param subscription_feeder [PgEventstore::SUbscriptionFeeder]
21
+ # @param subscription_feeder [PgEventstore::SubscriptionFeeder]
20
22
  # @param runners [Array<PgEventstore::SubscriptionRunner>]
21
23
  def initialize(config_name, subscription_feeder, runners)
22
24
  @config_name = config_name
@@ -3,6 +3,8 @@
3
3
  module PgEventstore
4
4
  # @!visibility private
5
5
  class SubscriptionCommandQueries
6
+ # @!attribute connection
7
+ # @return [PgEventstore::Connection]
6
8
  attr_reader :connection
7
9
  private :connection
8
10
 
@@ -15,7 +17,7 @@ module PgEventstore
15
17
  # @param subscriptions_set_id [Integer]
16
18
  # @param command_name [String]
17
19
  # @param data [Hash]
18
- # @return [PgEventstore::SubscriptionRunnerCommands::Abstract]
20
+ # @return [PgEventstore::SubscriptionRunnerCommands::Base]
19
21
  def find_or_create_by(subscription_id:, subscriptions_set_id:, command_name:, data:)
20
22
  transaction_queries.transaction do
21
23
  find_by(subscription_id: subscription_id, subscriptions_set_id: subscriptions_set_id, command_name: command_name) ||
@@ -26,7 +28,7 @@ module PgEventstore
26
28
  # @param subscription_id [Integer]
27
29
  # @param subscriptions_set_id [Integer]
28
30
  # @param command_name [String]
29
- # @return [PgEventstore::SubscriptionRunnerCommands::Abstract, nil]
31
+ # @return [PgEventstore::SubscriptionRunnerCommands::Base, nil]
30
32
  def find_by(subscription_id:, subscriptions_set_id:, command_name:)
31
33
  sql_builder =
32
34
  SQLBuilder.new.
@@ -48,7 +50,7 @@ module PgEventstore
48
50
  # @param subscriptions_set_id [Integer]
49
51
  # @param command_name [String]
50
52
  # @param data [Hash]
51
- # @return [PgEventstore::SubscriptionRunnerCommands::Abstract]
53
+ # @return [PgEventstore::SubscriptionRunnerCommands::Base]
52
54
  def create(subscription_id:, subscriptions_set_id:, command_name:, data:)
53
55
  sql = <<~SQL
54
56
  INSERT INTO subscription_commands (name, subscription_id, subscriptions_set_id, data)
@@ -63,7 +65,7 @@ module PgEventstore
63
65
 
64
66
  # @param subscription_ids [Array<Integer>]
65
67
  # @param subscriptions_set_id [Integer]
66
- # @return [Array<PgEventstore::SubscriptionRunnerCommands::Abstract>]
68
+ # @return [Array<PgEventstore::SubscriptionRunnerCommands::Base>]
67
69
  def find_commands(subscription_ids, subscriptions_set_id:)
68
70
  return [] if subscription_ids.empty?
69
71
 
@@ -3,6 +3,8 @@
3
3
  module PgEventstore
4
4
  # @!visibility private
5
5
  class SubscriptionQueries
6
+ # @!attribute connection
7
+ # @return [PgEventstore::Connection]
6
8
  attr_reader :connection
7
9
  private :connection
8
10
 
@@ -73,7 +75,7 @@ module PgEventstore
73
75
 
74
76
  # @param id [Integer]
75
77
  # @param attrs [Hash]
76
- # @param locked_by [Integer]
78
+ # @param locked_by [Integer, nil]
77
79
  # @return [Hash]
78
80
  # @raise [PgEventstore::RecordNotFound]
79
81
  # @raise [PgEventstore::WrongLockIdError]
@@ -118,7 +120,7 @@ module PgEventstore
118
120
  end
119
121
 
120
122
  # @param query_options [Hash{Integer => Hash}] runner_id/query options association
121
- # @return [Hash{Integer => Hash}] runner_id/events association
123
+ # @return [Hash{Integer => Array<Hash>}] runner_id/events association
122
124
  def subscriptions_events(query_options)
123
125
  return {} if query_options.empty?
124
126
 
@@ -3,6 +3,8 @@
3
3
  module PgEventstore
4
4
  # @!visibility private
5
5
  class SubscriptionsSetCommandQueries
6
+ # @!attribute connection
7
+ # @return [PgEventstore::Connection]
6
8
  attr_reader :connection
7
9
  private :connection
8
10
 
@@ -14,7 +16,7 @@ module PgEventstore
14
16
  # @param subscriptions_set_id [Integer]
15
17
  # @param command_name [String]
16
18
  # @param data [Hash]
17
- # @return [PgEventstore::SubscriptionFeederCommands::Abstract]
19
+ # @return [PgEventstore::SubscriptionFeederCommands::Base]
18
20
  def find_or_create_by(subscriptions_set_id:, command_name:, data:)
19
21
  transaction_queries.transaction do
20
22
  find_by(subscriptions_set_id: subscriptions_set_id, command_name: command_name) ||
@@ -24,7 +26,7 @@ module PgEventstore
24
26
 
25
27
  # @param subscriptions_set_id [Integer]
26
28
  # @param command_name [String]
27
- # @return [PgEventstore::SubscriptionFeederCommands::Abstract, nil]
29
+ # @return [PgEventstore::SubscriptionFeederCommands::Base, nil]
28
30
  def find_by(subscriptions_set_id:, command_name:)
29
31
  sql_builder =
30
32
  SQLBuilder.new.
@@ -42,7 +44,7 @@ module PgEventstore
42
44
  # @param subscriptions_set_id [Integer]
43
45
  # @param command_name [String]
44
46
  # @param data [Hash]
45
- # @return [PgEventstore::SubscriptionFeederCommands::Abstract]
47
+ # @return [PgEventstore::SubscriptionFeederCommands::Base]
46
48
  def create(subscriptions_set_id:, command_name:, data:)
47
49
  sql = <<~SQL
48
50
  INSERT INTO subscriptions_set_commands (name, subscriptions_set_id, data)
@@ -56,7 +58,7 @@ module PgEventstore
56
58
  end
57
59
 
58
60
  # @param subscriptions_set_id [Integer]
59
- # @return [Array<PgEventstore::SubscriptionFeederCommands::Abstract>]
61
+ # @return [Array<PgEventstore::SubscriptionFeederCommands::Base>]
60
62
  def find_commands(subscriptions_set_id)
61
63
  sql_builder =
62
64
  SQLBuilder.new.select('*').
@@ -3,6 +3,8 @@
3
3
  module PgEventstore
4
4
  # @!visibility private
5
5
  class SubscriptionsSetQueries
6
+ # @!attribute connection
7
+ # @return [PgEventstore::Connection]
6
8
  attr_reader :connection
7
9
  private :connection
8
10
 
@@ -63,6 +65,7 @@ module PgEventstore
63
65
 
64
66
  # @param id [Integer]
65
67
  # @param attrs [Hash]
68
+ # @return [Hash]
66
69
  def update(id, attrs)
67
70
  attrs = { updated_at: Time.now.utc }.merge(attrs)
68
71
  attrs_sql = attrs.keys.map.with_index(1) do |attr, index|
@@ -6,6 +6,7 @@ module PgEventstore
6
6
  class RunnerState
7
7
  include Extensions::CallbacksExtension
8
8
 
9
+ # @return [Hash<Symbol => String>]
9
10
  STATES = %i(initial running halting stopped dead).to_h { [_1, _1.to_s.freeze] }.freeze
10
11
 
11
12
  def initialize
@@ -7,20 +7,20 @@ module PgEventstore
7
7
  include Extensions::OptionsExtension
8
8
 
9
9
  # @!attribute id
10
- # @return [Integer]
10
+ # @return [Integer, nil]
11
11
  attribute(:id)
12
12
  # @!attribute set
13
- # @return [String] Subscription's set. Subscription should have unique pair of set and name.
13
+ # @return [String, nil] Subscription's set. Subscription should have unique pair of set and name.
14
14
  attribute(:set)
15
15
  # @!attribute name
16
- # @return [String] Subscription's name. Subscription should have unique pair of set and name.
16
+ # @return [String, nil] Subscription's name. Subscription should have unique pair of set and name.
17
17
  attribute(:name)
18
18
  # @!attribute total_processed_events
19
- # @return [Integer] total number of events, processed by this subscription
19
+ # @return [Integer, nil] total number of events, processed by this subscription
20
20
  attribute(:total_processed_events)
21
21
  # @!attribute options
22
- # @return [Hash] subscription's options to be used to query events. See {SubscriptionManager#subscribe} for the
23
- # list of available options
22
+ # @return [Hash, nil] subscription's options to be used to query events. See {SubscriptionManager#subscribe} for
23
+ # the list of available options
24
24
  attribute(:options)
25
25
  # @!attribute current_position
26
26
  # @return [Integer, nil] current Subscription's position. It is updated automatically each time an event is processed
@@ -34,29 +34,29 @@ module PgEventstore
34
34
  # processed by the Subscription per second.
35
35
  attribute(:average_event_processing_time)
36
36
  # @!attribute restart_count
37
- # @return [Integer] the number of Subscription's restarts after its failure
37
+ # @return [Integer, nil] the number of Subscription's restarts after its failure
38
38
  attribute(:restart_count)
39
39
  # @!attribute max_restarts_number
40
- # @return [Integer] maximum number of times the Subscription can be restarted
40
+ # @return [Integer, nil] maximum number of times the Subscription can be restarted
41
41
  attribute(:max_restarts_number)
42
42
  # @!attribute time_between_restarts
43
- # @return [Integer] interval in seconds between retries of failed Subscription
43
+ # @return [Integer, nil] interval in seconds between retries of failed Subscription
44
44
  attribute(:time_between_restarts)
45
45
  # @!attribute last_restarted_at
46
46
  # @return [Time, nil] last time the Subscription was restarted
47
47
  attribute(:last_restarted_at)
48
48
  # @!attribute last_error
49
- # @return [Hash{'class' => String, 'message' => String, 'backtrace' => Array<String>}, nil] the information about
49
+ # @return [Hash, nil] the information about
50
50
  # last error caused when processing events by the Subscription.
51
51
  attribute(:last_error)
52
52
  # @!attribute last_error_occurred_at
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 [Float] determines how often to pull events for the given Subscription in seconds
56
+ # @return [Integer, Float, nil] determines how often to pull events for the given Subscription in seconds
57
57
  attribute(:chunk_query_interval)
58
- # @!attribute chunk_query_interval
59
- # @return [Time] shows the time when last time events were fed to the event's processor
58
+ # @!attribute last_chunk_fed_at
59
+ # @return [Time, nil] shows the time when last time events were fed to the event's processor
60
60
  attribute(:last_chunk_fed_at)
61
61
  # @!attribute last_chunk_greatest_position
62
62
  # @return [Integer, nil] shows the greatest global_position of the last event in the last chunk fed to the event's
@@ -67,15 +67,15 @@ module PgEventstore
67
67
  # means that the Subscription isn't locked yet by any subscription manager.
68
68
  attribute(:locked_by)
69
69
  # @!attribute created_at
70
- # @return [Time]
70
+ # @return [Time, nil]
71
71
  attribute(:created_at)
72
72
  # @!attribute updated_at
73
- # @return [Time]
73
+ # @return [Time, nil]
74
74
  attribute(:updated_at)
75
75
 
76
76
  class << self
77
77
  # @param subscriptions_set_id [Integer] SubscriptionsSet#id
78
- # @param subscriptions [Array<PgEventstoreSubscription>]
78
+ # @param subscriptions [Array<PgEventstore::Subscription>]
79
79
  # @return [void]
80
80
  def ping_all(subscriptions_set_id, subscriptions)
81
81
  result = subscription_queries.ping_all(subscriptions_set_id, subscriptions.map(&:id))
@@ -111,6 +111,8 @@ module PgEventstore
111
111
  end
112
112
 
113
113
  # Locks the Subscription by the given lock id
114
+ # @param lock_id [Integer] SubscriptionsSet#id
115
+ # @param force [Boolean]
114
116
  # @return [PgEventstore::Subscription]
115
117
  def lock!(lock_id, force: false)
116
118
  self.id = subscription_queries.find_or_create_by(set: set, name: name)[:id]
@@ -144,7 +146,7 @@ module PgEventstore
144
146
  hash == another.hash
145
147
  end
146
148
 
147
- # @param another [PgEventstore::SubscriptionsSet]
149
+ # @param another [Object]
148
150
  # @return [Boolean]
149
151
  def ==(another)
150
152
  return false unless another.is_a?(Subscription)
@@ -6,6 +6,7 @@ module PgEventstore
6
6
  class SubscriptionFeeder
7
7
  extend Forwardable
8
8
 
9
+ # @return [Integer] number of seconds between heartbeat updates
9
10
  HEARTBEAT_INTERVAL = 10 # seconds
10
11
 
11
12
  def_delegators :subscriptions_set, :id
@@ -30,6 +31,7 @@ module PgEventstore
30
31
 
31
32
  # Adds SubscriptionRunner to the set
32
33
  # @param runner [PgEventstore::SubscriptionRunner]
34
+ # @return [PgEventstore::SubscriptionRunner]
33
35
  def add(runner)
34
36
  assert_proper_state!
35
37
  @runners.push(runner)
@@ -56,6 +58,7 @@ module PgEventstore
56
58
 
57
59
  # Sets the force_lock flash to true. If set - all related Subscriptions will ignore their lock state and will be
58
60
  # locked by the new SubscriptionsSet.
61
+ # @return [void]
59
62
  def force_lock!
60
63
  @force_lock = true
61
64
  end
@@ -170,6 +173,7 @@ module PgEventstore
170
173
  @commands_handler.stop
171
174
  end
172
175
 
176
+ # @param state [String]
173
177
  # @return [void]
174
178
  def update_subscriptions_set_state(state)
175
179
  subscriptions_set.update(state: state)
@@ -8,19 +8,19 @@ module PgEventstore
8
8
  include Extensions::BaseCommandExtension
9
9
 
10
10
  # @!attribute id
11
- # @return [Integer]
11
+ # @return [Integer, nil]
12
12
  attribute(:id)
13
13
  # @!attribute name
14
14
  # @return [String]
15
15
  attribute(:name) { self.class.name.split('::').last }
16
16
  # @!attribute subscriptions_set_id
17
- # @return [Integer]
17
+ # @return [Integer, nil]
18
18
  attribute(:subscriptions_set_id)
19
19
  # @!attribute data
20
- # @return [Hash]
20
+ # @return [Hash, nil]
21
21
  attribute(:data) { {} }
22
22
  # @!attribute created_at
23
- # @return [Time]
23
+ # @return [Time, nil]
24
24
  attribute(:created_at)
25
25
 
26
26
  # @param subscription_feeder [PgEventstore::SubscriptionFeeder]
@@ -9,6 +9,7 @@ module PgEventstore
9
9
  class SubscriptionHandlerPerformance
10
10
  extend Forwardable
11
11
 
12
+ # @return [Integer] the number of measurements to keep
12
13
  TIMINGS_TO_KEEP = 100
13
14
 
14
15
  def_delegators :@lock, :synchronize
@@ -33,7 +34,7 @@ module PgEventstore
33
34
  # The average time required to process an event.
34
35
  # @return [Float]
35
36
  def average_event_processing_time
36
- synchronize { @timings.size.zero? ? 0 : @timings.sum / @timings.size }
37
+ synchronize { @timings.size.zero? ? 0.0 : @timings.sum / @timings.size }
37
38
  end
38
39
  end
39
40
  end
@@ -10,10 +10,15 @@ module PgEventstore
10
10
  class SubscriptionRunner
11
11
  extend Forwardable
12
12
 
13
+ # @return [Integer]
13
14
  MAX_EVENTS_PER_CHUNK = 1_000
15
+ # @return [Integer]
14
16
  MIN_EVENTS_PER_CHUNK = 10
17
+ # @return [Integer]
15
18
  INITIAL_EVENTS_PER_CHUNK = 10
16
19
 
20
+ # @!attribute subscription
21
+ # @return [PgEventstore::Subscription]
17
22
  attr_reader :subscription
18
23
 
19
24
  def_delegators :@events_processor, :start, :stop, :stop_async, :feed, :wait_for_finish, :restore, :state, :running?,
@@ -8,22 +8,22 @@ module PgEventstore
8
8
  include Extensions::BaseCommandExtension
9
9
 
10
10
  # @!attribute id
11
- # @return [Integer]
11
+ # @return [Integer, nil]
12
12
  attribute(:id)
13
13
  # @!attribute name
14
14
  # @return [String]
15
15
  attribute(:name) { self.class.name.split('::').last }
16
16
  # @!attribute subscription_id
17
- # @return [Integer]
17
+ # @return [Integer, nil]
18
18
  attribute(:subscription_id)
19
19
  # @!attribute subscriptions_set_id
20
- # @return [Integer]
20
+ # @return [Integer, nil]
21
21
  attribute(:subscriptions_set_id)
22
22
  # @!attribute data
23
23
  # @return [Hash]
24
24
  attribute(:data) { {} }
25
25
  # @!attribute created_at
26
- # @return [Time]
26
+ # @return [Time, nil]
27
27
  attribute(:created_at)
28
28
 
29
29
  # @param subscription_runner [PgEventstore::SubscriptionRunner]
@@ -25,6 +25,8 @@ module PgEventstore
25
25
  class SubscriptionsManager
26
26
  extend Forwardable
27
27
 
28
+ # @!attribute config
29
+ # @return [PgEventstore::Config]
28
30
  attr_reader :config
29
31
  private :config
30
32
 
@@ -55,10 +57,10 @@ module PgEventstore
55
57
  # @option options [Hash] :filter provide it to filter events. It works the same way as a :filter option of
56
58
  # {PgEventstore::Client#read} method. Filtering by both - event types and streams are available.
57
59
  # @param middlewares [Array<Symbol>, nil] provide a list of middleware names to override a config's middlewares
58
- # @param pull_interval [Integer] an interval in seconds to determine how often to query new events of the given
59
- # subscription.
60
+ # @param pull_interval [Integer, Float] an interval in seconds to determine how often to query new events of the
61
+ # given subscription.
60
62
  # @param max_retries [Integer] max number of retries of failed Subscription
61
- # @param retries_interval [Float] a delay between retries of failed Subscription
63
+ # @param retries_interval [Integer, Float] a delay between retries of failed Subscription
62
64
  # @param restart_terminator [#call, nil] a callable object which, when called - accepts PgEventstore::Subscription
63
65
  # object to determine whether restarts should be stopped(true - stops restarts, false - continues restarts)
64
66
  # @return [void]
@@ -103,7 +105,7 @@ module PgEventstore
103
105
  end
104
106
 
105
107
  # @param middlewares [Array, nil]
106
- # @return [Array<Object<#serialize, #deserialize>>]
108
+ # @return [Array<PgEventstore::Middleware>]
107
109
  def select_middlewares(middlewares = nil)
108
110
  return config.middlewares.values unless middlewares
109
111
 
@@ -22,38 +22,38 @@ module PgEventstore
22
22
  end
23
23
 
24
24
  # @!attribute id
25
- # @return [Integer] It is used to lock the Subscription by updating Subscription#locked_by attribute
25
+ # @return [Integer, nil] It is used to lock the Subscription by updating Subscription#locked_by attribute
26
26
  attribute(:id)
27
27
  # @!attribute name
28
- # @return [String] name of the set
28
+ # @return [String, nil] name of the set
29
29
  attribute(:name)
30
30
  # @!attribute state
31
- # @return [String]
31
+ # @return [String, nil]
32
32
  attribute(:state)
33
33
  # @!attribute restart_count
34
- # @return [Integer] the number of SubscriptionsSet's restarts after its failure
34
+ # @return [Integer, nil] the number of SubscriptionsSet's restarts after its failure
35
35
  attribute(:restart_count)
36
36
  # @!attribute max_restarts_number
37
- # @return [Integer] maximum number of times the SubscriptionsSet can be restarted
37
+ # @return [Integer, nil] maximum number of times the SubscriptionsSet can be restarted
38
38
  attribute(:max_restarts_number)
39
39
  # @!attribute time_between_restarts
40
- # @return [Integer] interval in seconds between retries of failed SubscriptionsSet
40
+ # @return [Integer, nil] interval in seconds between retries of failed SubscriptionsSet
41
41
  attribute(:time_between_restarts)
42
42
  # @!attribute last_restarted_at
43
43
  # @return [Time, nil] last time the SubscriptionsSet was restarted
44
44
  attribute(:last_restarted_at)
45
45
  # @!attribute last_error
46
- # @return [Hash{'class' => String, 'message' => String, 'backtrace' => Array<String>}, nil] the information about
46
+ # @return [Hash, nil] the information about
47
47
  # last error caused when pulling Subscriptions events.
48
48
  attribute(:last_error)
49
49
  # @!attribute last_error_occurred_at
50
50
  # @return [Time, nil] the time when the last error occurred
51
51
  attribute(:last_error_occurred_at)
52
52
  # @!attribute created_at
53
- # @return [Time]
53
+ # @return [Time, nil]
54
54
  attribute(:created_at)
55
55
  # @!attribute updated_at
56
- # @return [Time]
56
+ # @return [Time, nil]
57
57
  attribute(:updated_at)
58
58
 
59
59
  # @param attrs [Hash]
@@ -100,7 +100,7 @@ module PgEventstore
100
100
  hash == another.hash
101
101
  end
102
102
 
103
- # @param another [PgEventstore::SubscriptionsSet]
103
+ # @param another [Object]
104
104
  # @return [Boolean]
105
105
  def ==(another)
106
106
  return false unless another.is_a?(SubscriptionsSet)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEventstore
4
- VERSION = "1.1.3"
4
+ # @return [String]
5
+ VERSION = "1.1.4"
5
6
  end
@@ -157,8 +157,8 @@ module PgEventstore
157
157
  validate_subscription_cmd(params[:cmd])
158
158
  cmd_class = SubscriptionRunnerCommands.command_class(params[:cmd])
159
159
  SubscriptionCommandQueries.new(connection).find_or_create_by(
160
- subscriptions_set_id: params[:set_id],
161
- subscription_id: params[:id],
160
+ subscriptions_set_id: Integer(params[:set_id]),
161
+ subscription_id: Integer(params[:id]),
162
162
  command_name: cmd_class.new.name,
163
163
  data: cmd_class.parse_data(Hash(params[:data]))
164
164
  )
@@ -170,7 +170,7 @@ module PgEventstore
170
170
  validate_subscriptions_set_cmd(params[:cmd])
171
171
  cmd_class = SubscriptionFeederCommands.command_class(params[:cmd])
172
172
  SubscriptionsSetCommandQueries.new(connection).find_or_create_by(
173
- subscriptions_set_id: params[:id],
173
+ subscriptions_set_id: Integer(params[:id]),
174
174
  command_name: cmd_class.new.name,
175
175
  data: cmd_class.parse_data(Hash(params[:data]))
176
176
  )
@@ -179,20 +179,20 @@ module PgEventstore
179
179
  end
180
180
 
181
181
  post '/delete_subscriptions_set/:id' do
182
- SubscriptionsSetQueries.new(connection).delete(params[:id])
182
+ SubscriptionsSetQueries.new(connection).delete(Integer(params[:id]))
183
183
 
184
184
  redirect redirect_back_url(fallback_url: url('/subscriptions'))
185
185
  end
186
186
 
187
187
  post '/delete_subscription/:id' do
188
- SubscriptionQueries.new(connection).delete(params[:id])
188
+ SubscriptionQueries.new(connection).delete(Integer(params[:id]))
189
189
 
190
190
  redirect redirect_back_url(fallback_url: url('/subscriptions'))
191
191
  end
192
192
 
193
193
  post '/delete_all_subscriptions' do
194
194
  params[:ids].each do |id|
195
- SubscriptionQueries.new(connection).delete(id)
195
+ SubscriptionQueries.new(connection).delete(Integer(id))
196
196
  end
197
197
 
198
198
  redirect redirect_back_url(fallback_url: url('/subscriptions'))
@@ -4,7 +4,21 @@ module PgEventstore
4
4
  module Web
5
5
  module Paginator
6
6
  class BaseCollection
7
- attr_reader :config_name, :starting_id, :per_page, :order, :options
7
+ # @!attribute config_name
8
+ # @return [Symbol]
9
+ attr_reader :config_name
10
+ # @!attribute starting_id
11
+ # @return [String, Integer, nil]
12
+ attr_reader :starting_id
13
+ # @!attribute per_page
14
+ # @return [Integer]
15
+ attr_reader :per_page
16
+ # @!attribute order
17
+ # @return [Symbol]
18
+ attr_reader :order
19
+ # @!attribute options
20
+ # @return [Hash]
21
+ attr_reader :options
8
22
 
9
23
  # @param config_name [Symbol]
10
24
  # @param starting_id [String, Integer, nil]
@@ -4,9 +4,10 @@ module PgEventstore
4
4
  module Web
5
5
  module Paginator
6
6
  class EventTypesCollection < BaseCollection
7
+ # @return [Integer]
7
8
  PER_PAGE = 10
8
9
 
9
- # @return [Array<Hash>]
10
+ # @return [Array<Hash<String => String>>]
10
11
  def collection
11
12
  @_collection ||=
12
13
  begin
@@ -4,17 +4,19 @@ module PgEventstore
4
4
  module Web
5
5
  module Paginator
6
6
  class EventsCollection < BaseCollection
7
+ # @return [Hash<String => Symbol>] SQL directions, string-to-symbol mapping
7
8
  SQL_DIRECTIONS = {
8
9
  'asc' => :asc,
9
10
  'desc' => :desc
10
11
  }.tap do |directions|
11
12
  directions.default = :desc
12
13
  end.freeze
14
+ # @return [Hash<String => Integer>] per page limits, string to Integer mapping
13
15
  PER_PAGE = %w[10 20 50 100 1000].to_h { [_1, _1.to_i] }.tap do |per_page|
14
16
  per_page.default = 10
15
17
  end.freeze
16
- # Max number of events after which we don't perform the exact count and keep the estimate count instead because of
17
- # the potential performance degradation.
18
+ # @return [Integer] max number of events after which we don't perform the exact count and keep the estimate
19
+ # count instead because of the potential performance degradation.
18
20
  MAX_NUMBER_TO_COUNT = 10_000
19
21
 
20
22
  # @return [Array<PgEventstore::Event>]
@@ -68,8 +70,8 @@ module PgEventstore
68
70
 
69
71
  private
70
72
 
71
- # @param event [PgEventstore::Eventg]
72
- # @return [integer, nil]
73
+ # @param event [PgEventstore::Event]
74
+ # @return [Integer, nil]
73
75
  def event_global_position(event)
74
76
  event&.link&.global_position || event&.global_position
75
77
  end
@@ -93,6 +95,7 @@ module PgEventstore
93
95
  end.to_a.first['count_all']
94
96
  end
95
97
 
98
+ # @param sql_builder [PgEventstore::SQLBuilder]
96
99
  # @return [Integer, nil]
97
100
  def global_position(sql_builder)
98
101
  connection.with do |conn|
@@ -4,7 +4,7 @@ module PgEventstore
4
4
  module Web
5
5
  module Paginator
6
6
  module Helpers
7
- # @param collection [PgEventstore::Paginator::BaseCollection]
7
+ # @param collection [PgEventstore::Web::Paginator::BaseCollection]
8
8
  # @return [String]
9
9
  def previous_page_link(collection)
10
10
  id = collection.prev_page_starting_id
@@ -16,7 +16,7 @@ module PgEventstore
16
16
  HTML
17
17
  end
18
18
 
19
- # @param collection [PgEventstore::Paginator::BaseCollection]
19
+ # @param collection [PgEventstore::Web::Paginator::BaseCollection]
20
20
  # @return [String]
21
21
  def next_page_link(collection)
22
22
  id = collection.next_page_starting_id
@@ -98,7 +98,7 @@ module PgEventstore
98
98
  private
99
99
 
100
100
  # @param starting_id [String, Integer, nil]
101
- # @param [String, nil]
101
+ # @return [String]
102
102
  def build_starting_id_link(starting_id)
103
103
  return 'javascript: void(0);' unless starting_id
104
104
 
@@ -4,9 +4,10 @@ module PgEventstore
4
4
  module Web
5
5
  module Paginator
6
6
  class StreamContextsCollection < BaseCollection
7
+ # @return [Integer]
7
8
  PER_PAGE = 10
8
9
 
9
- # @return [Array<Hash>]
10
+ # @return [Array<Hash<String => String>>]
10
11
  def collection
11
12
  @_collection ||=
12
13
  begin
@@ -4,9 +4,10 @@ module PgEventstore
4
4
  module Web
5
5
  module Paginator
6
6
  class StreamIdsCollection < BaseCollection
7
+ # @return [Integer]
7
8
  PER_PAGE = 10
8
9
 
9
- # @return [Array<Hash>]
10
+ # @return [Array<Hash<String => String>>]
10
11
  def collection
11
12
  @_collection ||=
12
13
  begin