pg_eventstore 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/pg_eventstore/extensions/callback_handlers_extension.rb +21 -0
  4. data/lib/pg_eventstore/subscriptions/callback_handlers/commands_handler_handlers.rb +38 -0
  5. data/lib/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rb +45 -0
  6. data/lib/pg_eventstore/subscriptions/callback_handlers/subscription_feeder_handlers.rb +103 -0
  7. data/lib/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rb +75 -0
  8. data/lib/pg_eventstore/subscriptions/commands_handler.rb +13 -29
  9. data/lib/pg_eventstore/subscriptions/events_processor.rb +17 -41
  10. data/lib/pg_eventstore/subscriptions/subscription_feeder.rb +77 -125
  11. data/lib/pg_eventstore/subscriptions/subscription_runner.rb +30 -55
  12. data/lib/pg_eventstore/subscriptions/subscriptions_lifecycle.rb +70 -0
  13. data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +8 -2
  14. data/lib/pg_eventstore/subscriptions/subscriptions_set_lifecycle.rb +39 -0
  15. data/lib/pg_eventstore/utils.rb +8 -0
  16. data/lib/pg_eventstore/version.rb +1 -1
  17. data/lib/pg_eventstore/web/application.rb +9 -1
  18. data/lib/pg_eventstore/web/paginator/events_collection.rb +1 -3
  19. data/lib/pg_eventstore/web/paginator/helpers.rb +4 -1
  20. data/lib/pg_eventstore/web/public/javascripts/pg_eventstore.js +10 -1
  21. data/lib/pg_eventstore/web/subscriptions/helpers.rb +3 -4
  22. data/lib/pg_eventstore/web/views/home/dashboard.erb +11 -0
  23. data/lib/pg_eventstore/web/views/home/partials/events.erb +6 -1
  24. data/lib/pg_eventstore/web/views/subscriptions/index.erb +2 -2
  25. data/lib/pg_eventstore.rb +1 -0
  26. data/sig/interfaces/_raw_event_handler.rbs +3 -0
  27. data/sig/pg_eventstore/extensions/callback_handlers_extension.rbs +11 -0
  28. data/sig/pg_eventstore/subscriptions/callback_handlers/commands_handler_handlers.rbs +10 -0
  29. data/sig/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rbs +11 -0
  30. data/sig/pg_eventstore/subscriptions/callback_handlers/subscription_feeder_handlers.rbs +31 -0
  31. data/sig/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rbs +19 -0
  32. data/sig/pg_eventstore/subscriptions/events_processor.rbs +1 -1
  33. data/sig/pg_eventstore/subscriptions/subscription_feeder.rbs +2 -30
  34. data/sig/pg_eventstore/subscriptions/subscriptions_lifecycle.rbs +27 -0
  35. data/sig/pg_eventstore/subscriptions/subscriptions_manager.rbs +1 -1
  36. data/sig/pg_eventstore/subscriptions/subscriptions_set_lifecycle.rbs +24 -0
  37. data/sig/pg_eventstore/utils.rbs +2 -0
  38. data/sig/pg_eventstore/web/subscriptions/helpers.rbs +1 -1
  39. metadata +17 -2
@@ -5,7 +5,12 @@
5
5
  <td><%= event.stream.context %></td>
6
6
  <td><%= event.stream.stream_name %></td>
7
7
  <td><a href="<%= stream_path(event) %>"><%= event.stream.stream_id %></a></td>
8
- <td><%= event.type %></td>
8
+ <td>
9
+ <%= event.type %>
10
+ <% if event.link %>
11
+ <i class="fa fa-link"></i>
12
+ <% end %>
13
+ </td>
9
14
  <td><%= event.created_at.strftime('%F %T') %></td>
10
15
  <td><%= event.id %></td>
11
16
  <td><a href="javascript: void(0);" class="d-inline-block text-nowrap toggle-event-data">JSON <i
@@ -66,7 +66,7 @@
66
66
  <tbody>
67
67
  <tr>
68
68
  <td><%= subscriptions_set.id %></td>
69
- <td><%= colored_state(subscriptions_set.state, subscriptions_set.updated_at) %></td>
69
+ <td><%= colored_state(subscriptions_set.state, PgEventstore::SubscriptionsSetLifecycle::HEARTBEAT_INTERVAL, subscriptions_set.updated_at) %></td>
70
70
  <td><%= subscriptions_set.restart_count %></td>
71
71
  <td><%= subscriptions_set.max_restarts_number %></td>
72
72
  <td><%= subscriptions_set.time_between_restarts %>s</td>
@@ -161,7 +161,7 @@
161
161
  <td><%= subscription.current_position %></td>
162
162
  <td><%= subscription.chunk_query_interval %>s</td>
163
163
  <td><%= subscription.last_chunk_fed_at %></td>
164
- <td><%= colored_state(subscription.state, subscription.updated_at) %></td>
164
+ <td><%= colored_state(subscription.state, PgEventstore::SubscriptionsLifecycle::HEARTBEAT_INTERVAL, subscription.updated_at) %></td>
165
165
  <td>
166
166
  <% if subscription.average_event_processing_time %>
167
167
  <%= "#{(1 / subscription.average_event_processing_time).to_i}/s" %>
data/lib/pg_eventstore.rb CHANGED
@@ -5,6 +5,7 @@ require_relative 'pg_eventstore/utils'
5
5
  require_relative 'pg_eventstore/callbacks'
6
6
  require_relative 'pg_eventstore/extensions/options_extension'
7
7
  require_relative 'pg_eventstore/extensions/callbacks_extension'
8
+ require_relative 'pg_eventstore/extensions/callback_handlers_extension'
8
9
  require_relative 'pg_eventstore/extensions/using_connection_extension'
9
10
  require_relative 'pg_eventstore/event_class_resolver'
10
11
  require_relative 'pg_eventstore/config'
@@ -0,0 +1,3 @@
1
+ interface _RawEventHandler
2
+ def call: (Hash[String, untyped] event) -> void
3
+ end
@@ -0,0 +1,11 @@
1
+ module PgEventstore
2
+ module Extensions
3
+ module CallbackHandlersExtension
4
+ def self.included: (untyped klass) -> untyped
5
+
6
+ module ClassMethods
7
+ def setup_handler: (Symbol name, *untyped args) -> ^(*untyped rest) -> untyped
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module PgEventstore
2
+ class CommandsHandlerHandlers
3
+ def self.process_feeder_commands: (Symbol config_name, PgEventstore::SubscriptionFeeder subscription_feeder) -> void
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
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module PgEventstore
2
+ class EventsProcessorHandlers
3
+ def self.process_event: (PgEventstore::Callbacks callbacks, _RawEventHandler handler, Array[Hash[untyped, untyped]] raw_events) -> void
4
+
5
+ def self.after_runner_died: (PgEventstore::Callbacks callbacks, StandardError error) -> void
6
+
7
+ def self.before_runner_restored: (PgEventstore::Callbacks callbacks) -> void
8
+
9
+ def self.change_state: (PgEventstore::Callbacks callbacks, String state) -> void
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ module PgEventstore
2
+ class SubscriptionFeederHandlers
3
+ include PgEventstore::Extensions::CallbackHandlersExtension
4
+
5
+ def self.update_subscriptions_set_state: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle, String state) -> void
6
+
7
+ def self.lock_subscriptions: (PgEventstore::SubscriptionsLifecycle subscriptions_lifecycle) -> void
8
+
9
+ def self.start_runners: (PgEventstore::SubscriptionsLifecycle subscriptions_lifecycle) -> void
10
+
11
+ def self.start_cmds_handler: (PgEventstore::CommandsHandler cmds_handler) -> void
12
+
13
+ def self.persist_error_info: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle, StandardError error) -> void
14
+
15
+ def self.restart_runner: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle, PgEventstore::BasicRunner basic_runner, StandardError _error) -> void
16
+
17
+ def self.ping_subscriptions_set: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle) -> void
18
+
19
+ def self.feed_runners: (PgEventstore::SubscriptionsLifecycle subscriptions_lifecycle, Symbol config_name) -> void
20
+
21
+ def self.ping_subscriptions: (PgEventstore::SubscriptionsLifecycle subscriptions_lifecycle) -> void
22
+
23
+ def self.stop_runners: (PgEventstore::SubscriptionsLifecycle subscriptions_lifecycle) -> void
24
+
25
+ def self.reset_subscriptions_set: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle) -> void
26
+
27
+ def self.stop_commands_handler: (PgEventstore::CommandsHandler cmds_handler) -> void
28
+
29
+ def self.update_subscriptions_set_restarts: (PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle) -> void
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module PgEventstore
2
+ class SubscriptionRunnerHandlers
3
+ def self.track_exec_time: (PgEventstore::SubscriptionHandlerPerformance stats, ^() -> void, Integer _current_position) -> void
4
+
5
+ def self.update_subscription_stats: (PgEventstore::Subscription subscription, PgEventstore::SubscriptionHandlerPerformance stats, Integer current_position) -> void
6
+
7
+ def self.update_subscription_error: (PgEventstore::Subscription subscription, StandardError error) -> void
8
+
9
+ def self.restart_events_processor: (PgEventstore::Subscription subscription, _RestartTerminator? restart_terminator,
10
+ _FailedSubscriptionNotifier? failed_subscription_notifier, PgEventstore::EventsProcessor events_processor,
11
+ StandardError error) -> void
12
+
13
+ def self.update_subscription_chunk_stats: (PgEventstore::Subscription subscription, Integer global_position) -> void
14
+
15
+ def self.update_subscription_restarts: (PgEventstore::Subscription subscription) -> void
16
+
17
+ def self.update_subscription_state: (PgEventstore::Subscription subscription, String state) -> void
18
+ end
19
+ end
@@ -4,7 +4,7 @@ module PgEventstore
4
4
  extend Forwardable
5
5
 
6
6
  # _@param_ `handler`
7
- %a{rbs:test:skip} def initialize: (_SubscriptionHandler handler, graceful_shutdown_timeout: Float | Integer) -> void
7
+ %a{rbs:test:skip} def initialize: (_RawEventHandler handler, graceful_shutdown_timeout: Float | Integer) -> void
8
8
 
9
9
  # _@param_ `raw_events`
10
10
  def feed: (::Array[::Hash[untyped, untyped]] raw_events) -> void
@@ -1,7 +1,6 @@
1
1
  module PgEventstore
2
2
  class SubscriptionFeeder
3
3
  extend Forwardable
4
- HEARTBEAT_INTERVAL: Integer
5
4
 
6
5
  # _@param_ `config_name`
7
6
  #
@@ -17,6 +16,8 @@ module PgEventstore
17
16
  retries_interval: Integer
18
17
  ) -> void
19
18
 
19
+ def id: () -> Integer
20
+
20
21
  # _@param_ `runner`
21
22
  def add: (PgEventstore::SubscriptionRunner runner) -> PgEventstore::SubscriptionRunner
22
23
 
@@ -24,41 +25,12 @@ module PgEventstore
24
25
 
25
26
  def stop_all: () -> void
26
27
 
27
- def force_lock!: () -> void
28
-
29
28
  def read_only_subscriptions: () -> ::Array[PgEventstore::Subscription]
30
29
 
31
30
  def read_only_subscriptions_set: () -> PgEventstore::SubscriptionsSet?
32
31
 
33
- def lock_all: () -> void
34
-
35
- def subscriptions_set: () -> PgEventstore::SubscriptionsSet
36
-
37
- def feeder: () -> PgEventstore::SubscriptionRunnersFeeder
38
-
39
32
  def attach_runner_callbacks: () -> void
40
33
 
41
- def before_runner_started: () -> void
42
-
43
- # _@param_ `error`
44
- def after_runner_died: (StandardError error) -> void
45
-
46
- # _@param_ `_error`
47
- def restart_runner: (StandardError _error) -> void
48
-
49
- def update_runner_restarts: () -> void
50
-
51
- def process_async: () -> void
52
-
53
- def ping_subscriptions_set: () -> void
54
-
55
- def ping_subscriptions: () -> void
56
-
57
- def after_runner_stopped: () -> void
58
-
59
- # _@param_ `state`
60
- def update_subscriptions_set_state: (String state) -> void
61
-
62
34
  def assert_proper_state!: () -> void
63
35
  end
64
36
  end
@@ -0,0 +1,27 @@
1
+ module PgEventstore
2
+ class SubscriptionsLifecycle
3
+ HEARTBEAT_INTERVAL: Integer
4
+
5
+ @config_name: Symbol
6
+
7
+ @subscriptions_set_lifecycle: PgEventstore::SubscriptionsSetLifecycle
8
+
9
+ @subscriptions_pinged_at: Time
10
+
11
+ @force_lock: bool
12
+
13
+ attr_reader runners: Array[PgEventstore::SubscriptionRunner]
14
+
15
+ def initialize: (Symbol config_name, PgEventstore::SubscriptionsSetLifecycle subscriptions_set_lifecycle)-> void
16
+
17
+ def force_locked?: -> bool
18
+
19
+ def lock_all: -> void
20
+
21
+ def ping_subscriptions: -> void
22
+
23
+ def subscriptions: -> Array[PgEventstore::Subscription]
24
+
25
+ def force_lock!: -> void
26
+ end
27
+ end
@@ -53,7 +53,7 @@ module PgEventstore
53
53
  # _@param_ `middlewares`
54
54
  #
55
55
  # _@param_ `handler`
56
- def create_event_handler: (::Array[Symbol]? middlewares, untyped handler) -> Proc
56
+ def create_raw_event_handler: (::Array[Symbol]? middlewares, _SubscriptionHandler handler) -> _RawEventHandler
57
57
 
58
58
  # _@param_ `middlewares`
59
59
  def select_middlewares: (?::Array[Symbol]? middlewares) -> ::Array[PgEventstore::Middleware]
@@ -0,0 +1,24 @@
1
+ module PgEventstore
2
+ class SubscriptionsSetLifecycle
3
+ HEARTBEAT_INTERVAL: Integer
4
+
5
+ type subscriptions_set_attrs_type = { name: String, max_restarts_number: Integer, time_between_restarts: Integer }
6
+
7
+ @config_name: Symbol
8
+
9
+ @subscriptions_set_attrs: subscriptions_set_attrs_type
10
+
11
+ @subscriptions_set_pinged_at: Time
12
+
13
+ attr_reader subscriptions_set: PgEventstore::SubscriptionsSet?
14
+
15
+
16
+ def initialize: (Symbol config_name, subscriptions_set_attrs_type subscriptions_set_attrs)-> void
17
+
18
+ def ping_subscriptions_set: -> void
19
+
20
+ def persisted_subscriptions_set: -> PgEventstore::SubscriptionsSet
21
+
22
+ def reset_subscriptions_set: -> void
23
+ end
24
+ end
@@ -16,5 +16,7 @@ module PgEventstore
16
16
 
17
17
  # _@param_ `str`
18
18
  def self.underscore_str: (String str) -> String
19
+
20
+ def self.original_global_position: (Hash[untyped, untyped] raw_event) -> Integer
19
21
  end
20
22
  end
@@ -42,7 +42,7 @@ module PgEventstore
42
42
  # _@param_ `updated_at`
43
43
  #
44
44
  # _@return_ — html status
45
- def colored_state: (String state, Time updated_at) -> String
45
+ def colored_state: (String state, Integer interval, Time updated_at) -> String
46
46
 
47
47
  # _@param_ `ids`
48
48
  def delete_all_subscriptions_url: (::Array[Integer] ids) -> String
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Dzyzenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-03 00:00:00.000000000 Z
11
+ date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -106,6 +106,7 @@ files:
106
106
  - lib/pg_eventstore/event_class_resolver.rb
107
107
  - lib/pg_eventstore/event_deserializer.rb
108
108
  - lib/pg_eventstore/event_serializer.rb
109
+ - lib/pg_eventstore/extensions/callback_handlers_extension.rb
109
110
  - lib/pg_eventstore/extensions/callbacks_extension.rb
110
111
  - lib/pg_eventstore/extensions/options_extension.rb
111
112
  - lib/pg_eventstore/extensions/using_connection_extension.rb
@@ -122,6 +123,10 @@ files:
122
123
  - lib/pg_eventstore/sql_builder.rb
123
124
  - lib/pg_eventstore/stream.rb
124
125
  - lib/pg_eventstore/subscriptions/basic_runner.rb
126
+ - lib/pg_eventstore/subscriptions/callback_handlers/commands_handler_handlers.rb
127
+ - lib/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rb
128
+ - lib/pg_eventstore/subscriptions/callback_handlers/subscription_feeder_handlers.rb
129
+ - lib/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rb
125
130
  - lib/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rb
126
131
  - lib/pg_eventstore/subscriptions/command_handlers/subscription_runners_commands.rb
127
132
  - lib/pg_eventstore/subscriptions/commands_handler.rb
@@ -150,8 +155,10 @@ files:
150
155
  - lib/pg_eventstore/subscriptions/subscription_runner_commands/start.rb
151
156
  - lib/pg_eventstore/subscriptions/subscription_runner_commands/stop.rb
152
157
  - lib/pg_eventstore/subscriptions/subscription_runners_feeder.rb
158
+ - lib/pg_eventstore/subscriptions/subscriptions_lifecycle.rb
153
159
  - lib/pg_eventstore/subscriptions/subscriptions_manager.rb
154
160
  - lib/pg_eventstore/subscriptions/subscriptions_set.rb
161
+ - lib/pg_eventstore/subscriptions/subscriptions_set_lifecycle.rb
155
162
  - lib/pg_eventstore/tasks/setup.rake
156
163
  - lib/pg_eventstore/utils.rb
157
164
  - lib/pg_eventstore/version.rb
@@ -201,6 +208,7 @@ files:
201
208
  - pg_eventstore.gemspec
202
209
  - rbs_collection.lock.yaml
203
210
  - rbs_collection.yaml
211
+ - sig/interfaces/_raw_event_handler.rbs
204
212
  - sig/interfaces/callback.rbs
205
213
  - sig/interfaces/event_class_resolver.rbs
206
214
  - sig/interfaces/event_modifier.rbs
@@ -229,6 +237,7 @@ files:
229
237
  - sig/pg_eventstore/event_class_resolver.rbs
230
238
  - sig/pg_eventstore/event_deserializer.rbs
231
239
  - sig/pg_eventstore/event_serializer.rbs
240
+ - sig/pg_eventstore/extensions/callback_handlers_extension.rbs
232
241
  - sig/pg_eventstore/extensions/callbacks_extension.rbs
233
242
  - sig/pg_eventstore/extensions/options_extension.rbs
234
243
  - sig/pg_eventstore/extensions/using_connection_extension.rbs
@@ -243,6 +252,10 @@ files:
243
252
  - sig/pg_eventstore/sql_builder.rbs
244
253
  - sig/pg_eventstore/stream.rbs
245
254
  - sig/pg_eventstore/subscriptions/basic_runner.rbs
255
+ - sig/pg_eventstore/subscriptions/callback_handlers/commands_handler_handlers.rbs
256
+ - sig/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rbs
257
+ - sig/pg_eventstore/subscriptions/callback_handlers/subscription_feeder_handlers.rbs
258
+ - sig/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rbs
246
259
  - sig/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rbs
247
260
  - sig/pg_eventstore/subscriptions/command_handlers/subscription_runners_commands.rbs
248
261
  - sig/pg_eventstore/subscriptions/commands_handler.rbs
@@ -271,8 +284,10 @@ files:
271
284
  - sig/pg_eventstore/subscriptions/subscription_runner_commands/start.rbs
272
285
  - sig/pg_eventstore/subscriptions/subscription_runner_commands/stop.rbs
273
286
  - sig/pg_eventstore/subscriptions/subscription_runners_feeder.rbs
287
+ - sig/pg_eventstore/subscriptions/subscriptions_lifecycle.rbs
274
288
  - sig/pg_eventstore/subscriptions/subscriptions_manager.rbs
275
289
  - sig/pg_eventstore/subscriptions/subscriptions_set.rbs
290
+ - sig/pg_eventstore/subscriptions/subscriptions_set_lifecycle.rbs
276
291
  - sig/pg_eventstore/utils.rbs
277
292
  - sig/pg_eventstore/version.rbs
278
293
  - sig/pg_eventstore/web/paginator/base_collection.rbs