forest_admin_datasource_rpc 1.16.2 → 1.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125dddf4e300c8f56852cef145cffa5402449cf4832a19c1d0602ebcb07cb733
4
- data.tar.gz: 8b791dc37bb3b2c1667c20f76e99b45c4de52b9aba6c7d34e227196d05955045
3
+ metadata.gz: be0a00b5ca26d9036b622fd38dad0f6578aa1aade7052c6375dcece422b83226
4
+ data.tar.gz: be0b96219b613b0511416f0f557b310348fe1889fc1497e0115d61d7eb250087
5
5
  SHA512:
6
- metadata.gz: 7bdc39e2196fad784f0929119d79162c580e58bb94282bd61a547e012c8642d9b0ec104a94224294ff0e139066dea9af7545565c3718c3436c89f6009245e491
7
- data.tar.gz: 9135542c6fa1a160b46bb634ef3dfba2d1f102d26913929dcea52942dfd4cf95ebd9b569234a24079ebe0ddec75178da1170de82805bb02e7f8b6cdd21d4ec1a
6
+ metadata.gz: 63d1a2248a321c38f59cfbed6ea2d924710c29a33f65245634f3369c70c08524959cbc898d06d56db14b459133aa8d1888eeed90c46ec1e67244e62a7e8e36b3
7
+ data.tar.gz: 911a400b9b6f9efc37bb3135f1c0ce357e91793f20204a364db166342af466503288215e531e98dcd90e23637e773b795b6ac20e3e0ce46272b9efca49c92331
@@ -2,7 +2,7 @@ module ForestAdminDatasourceRpc
2
2
  class Datasource < ForestAdminDatasourceToolkit::Datasource
3
3
  include ForestAdminDatasourceRpc::Utils
4
4
 
5
- def initialize(options, introspection)
5
+ def initialize(options, introspection, sse_client = nil)
6
6
  super()
7
7
 
8
8
  ForestAdminAgent::Facades::Container.logger.log(
@@ -18,6 +18,8 @@ module ForestAdminDatasourceRpc
18
18
  @options = options
19
19
  @charts = introspection[:charts]
20
20
  @rpc_relations = introspection[:rpc_relations]
21
+ @sse_client = sse_client
22
+ @cleaned_up = false
21
23
 
22
24
  native_query_connections = introspection[:native_query_connections] || []
23
25
  @live_query_connections = native_query_connections.to_h { |conn| [conn[:name], conn[:name]] }
@@ -50,5 +52,22 @@ module ForestAdminDatasourceRpc
50
52
  payload: { connection_name: connection_name, query: query, binds: binds })
51
53
  ForestAdminDatasourceToolkit::Utils::HashHelper.convert_keys(result.to_a)
52
54
  end
55
+
56
+ def cleanup
57
+ return if @cleaned_up
58
+
59
+ @cleaned_up = true
60
+
61
+ if @sse_client
62
+ ForestAdminAgent::Facades::Container.logger&.log('Info', '[RPCDatasource] Closing SSE connection...')
63
+ @sse_client.close
64
+ ForestAdminAgent::Facades::Container.logger&.log('Info', '[RPCDatasource] SSE connection closed')
65
+ end
66
+ rescue StandardError => e
67
+ ForestAdminAgent::Facades::Container.logger&.log(
68
+ 'Error',
69
+ "[RPCDatasource] Error during cleanup: #{e.class} - #{e.message}"
70
+ )
71
+ end
53
72
  end
54
73
  end
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceRpc
2
- VERSION = "1.16.2"
2
+ VERSION = "1.16.3"
3
3
  end
@@ -55,7 +55,44 @@ module ForestAdminDatasourceRpc
55
55
  end
56
56
  sse.start
57
57
 
58
- ForestAdminDatasourceRpc::Datasource.new(options, schema)
58
+ datasource = ForestAdminDatasourceRpc::Datasource.new(options, schema, sse)
59
+
60
+ # Setup cleanup hooks for proper SSE client shutdown
61
+ setup_cleanup_hooks(datasource)
62
+
63
+ datasource
64
+ end
65
+ end
66
+
67
+ def self.setup_cleanup_hooks(datasource)
68
+ # Register cleanup handler for graceful shutdown
69
+ at_exit do
70
+ datasource.cleanup
71
+ rescue StandardError => e
72
+ # Silently ignore errors during exit cleanup to prevent test pollution
73
+ warn "[RPCDatasource] Error during at_exit cleanup: #{e.message}" if $VERBOSE
74
+ end
75
+
76
+ # Handle SIGINT (Ctrl+C)
77
+ Signal.trap('INT') do
78
+ begin
79
+ ForestAdminAgent::Facades::Container.logger&.log('Info', '[RPCDatasource] Received SIGINT, cleaning up...')
80
+ rescue StandardError
81
+ # Logger might not be available
82
+ end
83
+ datasource.cleanup
84
+ exit(0)
85
+ end
86
+
87
+ # Handle SIGTERM (default kill signal)
88
+ Signal.trap('TERM') do
89
+ begin
90
+ ForestAdminAgent::Facades::Container.logger&.log('Info', '[RPCDatasource] Received SIGTERM, cleaning up...')
91
+ rescue StandardError
92
+ # Logger might not be available
93
+ end
94
+ datasource.cleanup
95
+ exit(0)
59
96
  end
60
97
  end
61
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_datasource_rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.2
4
+ version: 1.16.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu