pg_eventstore 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +7 -29
  4. data/docs/admin_ui.md +35 -0
  5. data/lib/pg_eventstore/abstract_command.rb +2 -0
  6. data/lib/pg_eventstore/callbacks.rb +3 -0
  7. data/lib/pg_eventstore/client.rb +6 -1
  8. data/lib/pg_eventstore/config.rb +1 -1
  9. data/lib/pg_eventstore/connection.rb +9 -1
  10. data/lib/pg_eventstore/errors.rb +45 -26
  11. data/lib/pg_eventstore/event.rb +2 -1
  12. data/lib/pg_eventstore/event_class_resolver.rb +1 -1
  13. data/lib/pg_eventstore/event_deserializer.rb +8 -2
  14. data/lib/pg_eventstore/event_serializer.rb +2 -0
  15. data/lib/pg_eventstore/extensions/callbacks_extension.rb +1 -0
  16. data/lib/pg_eventstore/extensions/options_extension.rb +3 -1
  17. data/lib/pg_eventstore/queries/event_queries.rb +12 -4
  18. data/lib/pg_eventstore/queries/links_resolver.rb +3 -0
  19. data/lib/pg_eventstore/queries/partition_queries.rb +6 -0
  20. data/lib/pg_eventstore/queries/transaction_queries.rb +4 -0
  21. data/lib/pg_eventstore/queries.rb +1 -1
  22. data/lib/pg_eventstore/query_builders/{events_filtering_query.rb → events_filtering.rb} +3 -0
  23. data/lib/pg_eventstore/sql_builder.rb +18 -10
  24. data/lib/pg_eventstore/stream.rb +13 -2
  25. data/lib/pg_eventstore/subscriptions/basic_runner.rb +2 -0
  26. data/lib/pg_eventstore/subscriptions/commands_handler.rb +5 -3
  27. data/lib/pg_eventstore/subscriptions/queries/subscription_command_queries.rb +6 -4
  28. data/lib/pg_eventstore/subscriptions/queries/subscription_queries.rb +4 -2
  29. data/lib/pg_eventstore/subscriptions/queries/subscriptions_set_command_queries.rb +6 -4
  30. data/lib/pg_eventstore/subscriptions/queries/subscriptions_set_queries.rb +3 -0
  31. data/lib/pg_eventstore/subscriptions/runner_state.rb +1 -0
  32. data/lib/pg_eventstore/subscriptions/subscription.rb +19 -17
  33. data/lib/pg_eventstore/subscriptions/subscription_feeder.rb +4 -0
  34. data/lib/pg_eventstore/subscriptions/subscription_feeder_commands/base.rb +4 -4
  35. data/lib/pg_eventstore/subscriptions/subscription_handler_performance.rb +2 -1
  36. data/lib/pg_eventstore/subscriptions/subscription_runner.rb +5 -0
  37. data/lib/pg_eventstore/subscriptions/subscription_runner_commands/base.rb +4 -4
  38. data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +6 -4
  39. data/lib/pg_eventstore/subscriptions/subscriptions_set.rb +10 -10
  40. data/lib/pg_eventstore/version.rb +2 -1
  41. data/lib/pg_eventstore/web/application.rb +12 -6
  42. data/lib/pg_eventstore/web/paginator/base_collection.rb +15 -1
  43. data/lib/pg_eventstore/web/paginator/event_types_collection.rb +2 -1
  44. data/lib/pg_eventstore/web/paginator/events_collection.rb +7 -4
  45. data/lib/pg_eventstore/web/paginator/helpers.rb +3 -3
  46. data/lib/pg_eventstore/web/paginator/stream_contexts_collection.rb +2 -1
  47. data/lib/pg_eventstore/web/paginator/stream_ids_collection.rb +2 -1
  48. data/lib/pg_eventstore/web/paginator/stream_names_collection.rb +2 -1
  49. data/lib/pg_eventstore/web/subscriptions/set_collection.rb +2 -0
  50. data/lib/pg_eventstore/web/subscriptions/subscriptions.rb +2 -0
  51. data/lib/pg_eventstore/web/subscriptions/subscriptions_set.rb +2 -0
  52. data/lib/pg_eventstore/web/subscriptions/subscriptions_to_set_association.rb +6 -1
  53. data/lib/pg_eventstore/web/views/layouts/application.erb +12 -12
  54. data/lib/pg_eventstore.rb +6 -1
  55. data/pg_eventstore.gemspec +1 -1
  56. data/rbs_collection.lock.yaml +16 -0
  57. data/rbs_collection.yaml +23 -0
  58. data/sig/interfaces/callback.rbs +3 -0
  59. data/sig/interfaces/event_class_resolver.rbs +3 -0
  60. data/sig/interfaces/event_modifier.rbs +3 -0
  61. data/sig/interfaces/restart_terminator.rbs +3 -0
  62. data/sig/interfaces/subscription_handler.rbs +3 -0
  63. data/sig/pg/basic_type_registry.rbs +21 -0
  64. data/sig/pg/connection.rbs +407 -0
  65. data/sig/pg/constants.rbs +153 -0
  66. data/sig/pg_eventstore/abstract_command.rbs +11 -0
  67. data/sig/pg_eventstore/callbacks.rbs +21 -0
  68. data/sig/pg_eventstore/client.rbs +67 -0
  69. data/sig/pg_eventstore/commands/append.rbs +33 -0
  70. data/sig/pg_eventstore/commands/event_modifiers/prepare_link_event.rbs +24 -0
  71. data/sig/pg_eventstore/commands/event_modifiers/prepare_regular_event.rbs +12 -0
  72. data/sig/pg_eventstore/commands/link_to.rbs +17 -0
  73. data/sig/pg_eventstore/commands/multiple.rbs +7 -0
  74. data/sig/pg_eventstore/commands/read.rbs +10 -0
  75. data/sig/pg_eventstore/commands/regular_stream_read_paginated.rbs +32 -0
  76. data/sig/pg_eventstore/commands/system_stream_read_paginated.rbs +30 -0
  77. data/sig/pg_eventstore/config.rbs +51 -0
  78. data/sig/pg_eventstore/connection.rbs +30 -0
  79. data/sig/pg_eventstore/errors.rbs +116 -0
  80. data/sig/pg_eventstore/event.rbs +46 -0
  81. data/sig/pg_eventstore/event_class_resolver.rbs +6 -0
  82. data/sig/pg_eventstore/event_deserializer.rbs +20 -0
  83. data/sig/pg_eventstore/event_serializer.rbs +13 -0
  84. data/sig/pg_eventstore/extensions/callbacks_extension.rbs +23 -0
  85. data/sig/pg_eventstore/extensions/options_extension.rbs +37 -0
  86. data/sig/pg_eventstore/extensions/using_connection_extension.rbs +14 -0
  87. data/sig/pg_eventstore/middleware.rbs +9 -0
  88. data/sig/pg_eventstore/pg_connection.rbs +13 -0
  89. data/sig/pg_eventstore/queries/event_queries.rbs +50 -0
  90. data/sig/pg_eventstore/queries/links_resolver.rbs +19 -0
  91. data/sig/pg_eventstore/queries/partition_queries.rbs +74 -0
  92. data/sig/pg_eventstore/queries/transaction_queries.rbs +21 -0
  93. data/sig/pg_eventstore/queries.rbs +23 -0
  94. data/sig/pg_eventstore/query_builders/events_filtering_query.rbs +62 -0
  95. data/sig/pg_eventstore/sql_builder.rbs +74 -0
  96. data/sig/pg_eventstore/stream.rbs +40 -0
  97. data/sig/pg_eventstore/subscriptions/basic_runner.rbs +37 -0
  98. data/sig/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rbs +16 -0
  99. data/sig/pg_eventstore/subscriptions/command_handlers/subscription_runners_commands.rbs +18 -0
  100. data/sig/pg_eventstore/subscriptions/commands_handler.rbs +25 -0
  101. data/sig/pg_eventstore/subscriptions/events_processor.rbs +34 -0
  102. data/sig/pg_eventstore/subscriptions/extensions/base_command_extension.rbs +20 -0
  103. data/sig/pg_eventstore/subscriptions/extensions/command_class_lookup_extension.rbs +8 -0
  104. data/sig/pg_eventstore/subscriptions/queries/subscription_command_queries.rbs +56 -0
  105. data/sig/pg_eventstore/subscriptions/queries/subscription_queries.rbs +73 -0
  106. data/sig/pg_eventstore/subscriptions/queries/subscriptions_set_command_queries.rbs +39 -0
  107. data/sig/pg_eventstore/subscriptions/queries/subscriptions_set_queries.rbs +36 -0
  108. data/sig/pg_eventstore/subscriptions/runner_state.rbs +16 -0
  109. data/sig/pg_eventstore/subscriptions/subscription.rbs +96 -0
  110. data/sig/pg_eventstore/subscriptions/subscription_feeder.rbs +64 -0
  111. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/base.rbs +45 -0
  112. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/restore.rbs +8 -0
  113. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/start_all.rbs +8 -0
  114. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/stop.rbs +8 -0
  115. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands/stop_all.rbs +8 -0
  116. data/sig/pg_eventstore/subscriptions/subscription_feeder_commands.rbs +8 -0
  117. data/sig/pg_eventstore/subscriptions/subscription_handler_performance.rbs +12 -0
  118. data/sig/pg_eventstore/subscriptions/subscription_runner.rbs +55 -0
  119. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/base.rbs +47 -0
  120. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/reset_position.rbs +11 -0
  121. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/restore.rbs +8 -0
  122. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/start.rbs +8 -0
  123. data/sig/pg_eventstore/subscriptions/subscription_runner_commands/stop.rbs +8 -0
  124. data/sig/pg_eventstore/subscriptions/subscription_runner_commands.rbs +8 -0
  125. data/sig/pg_eventstore/subscriptions/subscription_runners_feeder.rbs +13 -0
  126. data/sig/pg_eventstore/subscriptions/subscriptions_manager.rbs +60 -0
  127. data/sig/pg_eventstore/subscriptions/subscriptions_set.rbs +72 -0
  128. data/sig/pg_eventstore/utils.rbs +20 -0
  129. data/sig/pg_eventstore/version.rbs +3 -0
  130. data/sig/pg_eventstore/web/paginator/base_collection.rbs +51 -0
  131. data/sig/pg_eventstore/web/paginator/event_types_collection.rbs +15 -0
  132. data/sig/pg_eventstore/web/paginator/events_collection.rbs +31 -0
  133. data/sig/pg_eventstore/web/paginator/helpers.rbs +38 -0
  134. data/sig/pg_eventstore/web/paginator/stream_contexts_collection.rbs +15 -0
  135. data/sig/pg_eventstore/web/paginator/stream_ids_collection.rbs +15 -0
  136. data/sig/pg_eventstore/web/paginator/stream_names_collection.rbs +15 -0
  137. data/sig/pg_eventstore/web/subscriptions/helpers.rbs +48 -0
  138. data/sig/pg_eventstore/web/subscriptions/set_collection.rbs +18 -0
  139. data/sig/pg_eventstore/web/subscriptions/subscriptions.rbs +18 -0
  140. data/sig/pg_eventstore/web/subscriptions/subscriptions_set.rbs +18 -0
  141. data/sig/pg_eventstore/web/subscriptions/subscriptions_to_set_association.rbs +18 -0
  142. data/sig/pg_eventstore.rbs +42 -0
  143. metadata +91 -3
@@ -19,13 +19,13 @@ module PgEventstore
19
19
  end
20
20
 
21
21
  # @param sql [String]
22
- # @return self
22
+ # @return [self]
23
23
  def select(sql)
24
24
  @select_values.push(sql)
25
25
  self
26
26
  end
27
27
 
28
- # @return self
28
+ # @return [self]
29
29
  def unselect
30
30
  @select_values.clear
31
31
  self
@@ -33,7 +33,7 @@ module PgEventstore
33
33
 
34
34
  # @param sql [String]
35
35
  # @param arguments [Array] positional values
36
- # @return self
36
+ # @return [self]
37
37
  def where(sql, *arguments)
38
38
  @where_values['AND'].push([sql, arguments])
39
39
  self
@@ -41,14 +41,14 @@ module PgEventstore
41
41
 
42
42
  # @param sql [String]
43
43
  # @param arguments [Object] positional values
44
- # @return self
44
+ # @return [self]
45
45
  def where_or(sql, *arguments)
46
46
  @where_values['OR'].push([sql, arguments])
47
47
  self
48
48
  end
49
49
 
50
50
  # @param table_name [String]
51
- # @return self
51
+ # @return [self]
52
52
  def from(table_name)
53
53
  @from_value = table_name
54
54
  self
@@ -56,38 +56,40 @@ module PgEventstore
56
56
 
57
57
  # @param sql [String]
58
58
  # @param arguments [Object]
59
- # @return self
59
+ # @return [self]
60
60
  def join(sql, *arguments)
61
61
  @join_values.push([sql, arguments])
62
62
  self
63
63
  end
64
64
 
65
65
  # @param sql [String]
66
- # @return self
66
+ # @return [self]
67
67
  def order(sql)
68
68
  @order_values.push(sql)
69
69
  self
70
70
  end
71
71
 
72
+ # @return [self]
72
73
  def remove_order
73
74
  @order_values.clear
74
75
  self
75
76
  end
76
77
 
77
78
  # @param limit [Integer]
78
- # @return self
79
+ # @return [self]
79
80
  def limit(limit)
80
81
  @limit_value = limit.to_i
81
82
  self
82
83
  end
83
84
 
85
+ # @return [self]
84
86
  def remove_limit
85
87
  @limit_value = nil
86
88
  self
87
89
  end
88
90
 
89
91
  # @param offset [Integer]
90
- # @return self
92
+ # @return [self]
91
93
  def offset(offset)
92
94
  @offset_value = offset.to_i
93
95
  self
@@ -101,17 +103,19 @@ module PgEventstore
101
103
  end
102
104
 
103
105
  # @param sql [String]
104
- # @return self
106
+ # @return [self]
105
107
  def group(sql)
106
108
  @group_values.push(sql)
107
109
  self
108
110
  end
109
111
 
112
+ # @return [self]
110
113
  def remove_group
111
114
  @group_values.clear
112
115
  self
113
116
  end
114
117
 
118
+ # @return [Array<String, Array<Object>>]
115
119
  def to_exec_params
116
120
  @positional_values.clear
117
121
  @positional_values_size = 0
@@ -125,10 +129,13 @@ module PgEventstore
125
129
  @positional_values
126
130
  end
127
131
 
132
+ # @param val [Integer]
133
+ # @return [Integer]
128
134
  def positional_values_size=(val)
129
135
  @positional_values_size = val
130
136
  end
131
137
 
138
+ # @return [Array<String, Array<Object>>]
132
139
  def _to_exec_params
133
140
  return [single_query_sql, @positional_values] if @union_values.empty?
134
141
 
@@ -188,6 +195,7 @@ module PgEventstore
188
195
  end
189
196
 
190
197
  # Replaces "?" signs in the given string with positional variables and memorize positional values they refer to.
198
+ # @param sql [String]
191
199
  # @return [String]
192
200
  def extract_positional_args(sql, *arguments)
193
201
  sql.gsub("?").each_with_index do |_, index|
@@ -4,7 +4,9 @@ require 'digest/md5'
4
4
 
5
5
  module PgEventstore
6
6
  class Stream
7
+ # @return [String] a stream prefix of the system stream
7
8
  SYSTEM_STREAM_PREFIX = '$'
9
+ # @return [Integer]
8
10
  NON_EXISTING_STREAM_REVISION = -1
9
11
 
10
12
  class << self
@@ -18,7 +20,15 @@ module PgEventstore
18
20
  end
19
21
  end
20
22
 
21
- attr_reader :context, :stream_name, :stream_id
23
+ # @!attribute context
24
+ # @return [String]
25
+ attr_reader :context
26
+ # @!attribute stream_name
27
+ # @return [String]
28
+ attr_reader :stream_name
29
+ # @!attribute stream_id
30
+ # @return [String]
31
+ attr_reader :stream_id
22
32
 
23
33
  # @param context [String]
24
34
  # @param stream_name [String]
@@ -47,6 +57,7 @@ module PgEventstore
47
57
  alias to_a deconstruct
48
58
 
49
59
  # @param keys [Array<Symbol>, nil]
60
+ # @return [Hash<Symbol => String>]
50
61
  def deconstruct_keys(keys)
51
62
  hash = { context: context, stream_name: stream_name, stream_id: stream_id }
52
63
  return hash unless keys
@@ -72,7 +83,7 @@ module PgEventstore
72
83
  hash == another.hash
73
84
  end
74
85
 
75
- # @param other_stream [Stream]
86
+ # @param other_stream [Object]
76
87
  # @return [Boolean]
77
88
  def ==(other_stream)
78
89
  return false unless other_stream.is_a?(Stream)
@@ -219,10 +219,12 @@ module PgEventstore
219
219
  end
220
220
 
221
221
  # Delegates :change_state action to the runner
222
+ # @return [void]
222
223
  def delegate_change_state_cbx
223
224
  @state.define_callback(:change_state, :before, method(:change_state))
224
225
  end
225
226
 
227
+ # @return [void]
226
228
  def change_state(...)
227
229
  callbacks.run_callbacks(:change_state, ...)
228
230
  end
@@ -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.2"
4
+ # @return [String]
5
+ VERSION = "1.1.4"
5
6
  end