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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be0a00b5ca26d9036b622fd38dad0f6578aa1aade7052c6375dcece422b83226
|
|
4
|
+
data.tar.gz: be0b96219b613b0511416f0f557b310348fe1889fc1497e0115d61d7eb250087
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
@@ -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
|