feat(connection): notify sidebar when keepalive loses connection
This commit is contained in:
1 parent
3ffff92c8f
commit
dc503877f9
13 files changed
+864
-27
No files matched your search
@@ -75,6 +75,8 @@ export const sessionCredentialStatus = forward("sessionCredentialStatus");
|
||||
export const forgetSessionCredential = forward("forgetSessionCredential");
|
||||
export const replaceNacosSessionCredential = forward("replaceNacosSessionCredential");
|
||||
export const checkConnectionHealth = forward("checkConnectionHealth");
|
||||
export const connectionIsOpen = forward("connectionIsOpen");
|
||||
export const subscribeConnectionLiveness = forward("subscribeConnectionLiveness");
|
||||
export const prewarmConnection = forward("prewarmConnection");
|
||||
export const connectionIdentifierQuote = forward("connectionIdentifierQuote");
|
||||
export const closeDatabaseConnection = forward("closeDatabaseConnection");
|
||||
|
||||
@@ -249,6 +249,7 @@ import type { DataCompareFromTablesOptions, DataCompareFromTablesPreparation, Da
|
||||
import { apiUrl, apiWebSocketUrl } from "@/lib/common/webPath";
|
||||
import type {
|
||||
ActivePluginSession,
|
||||
ConnectionLivenessMessage,
|
||||
PluginBinaryEvent,
|
||||
PluginConnectionActionResult,
|
||||
PluginEvent,
|
||||
@@ -556,6 +557,17 @@ export async function checkConnectionHealth(connectionId: string): Promise<void>
|
||||
return post("/api/connection/check-health", { connectionId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only counterpart of `checkConnectionHealth`: reports whether the connection still has a
|
||||
* pool, without probing or mutating anything (#4339).
|
||||
*
|
||||
* Liveness events must be confirmed through this, never through `checkConnectionHealth`: the
|
||||
* latter removes unhealthy pools and is the path `ensureConnected` uses to trigger a reconnect.
|
||||
*/
|
||||
export async function connectionIsOpen(connectionId: string): Promise<boolean> {
|
||||
return post("/api/connection/is-open", { connectionId });
|
||||
}
|
||||
|
||||
export async function prewarmConnection(connectionId: string, database?: string, catalog?: string, clientSessionId?: string): Promise<void> {
|
||||
return post("/api/connection/prewarm", { connectionId, database, catalog, clientSessionId });
|
||||
}
|
||||
@@ -785,6 +797,20 @@ export async function subscribePluginEvents(onEvent: (event: PluginEvent) => voi
|
||||
return () => source.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to backend connection-liveness messages (#4339).
|
||||
*
|
||||
* The SSE payload is one `ConnectionLivenessMessage`: the plugin stream's `{ kind }` wrapper
|
||||
* multiplexes two streams, whereas here `kind` is the message's own discriminator.
|
||||
*/
|
||||
export async function subscribeConnectionLiveness(onEvent: (event: ConnectionLivenessMessage) => void): Promise<() => void> {
|
||||
const source = new EventSource(apiUrl("/api/connection/liveness-events"));
|
||||
source.onmessage = (message) => {
|
||||
onEvent(JSON.parse(message.data) as ConnectionLivenessMessage);
|
||||
};
|
||||
return () => source.close();
|
||||
}
|
||||
|
||||
async function pluginAssetPayload(path: string): Promise<PluginUiAssetPayload> {
|
||||
const response = await fetch(apiUrl(path));
|
||||
if (!response.ok) throw new Error(await response.text());
|
||||
|
||||
@@ -122,6 +122,7 @@ import type { QueryEditability } from "@/lib/sql/sqlAnalysis";
|
||||
import { isTerminalTransferProgress } from "@/lib/backend/transferProgress";
|
||||
import type {
|
||||
ActivePluginSession,
|
||||
ConnectionLivenessMessage,
|
||||
PluginBinaryEvent,
|
||||
PluginConnectionActionResult,
|
||||
PluginEvent,
|
||||
@@ -1563,6 +1564,17 @@ export async function checkConnectionHealth(connectionId: string): Promise<void>
|
||||
return invokeBackend("check_connection_health", { connectionId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only counterpart of `checkConnectionHealth`: reports whether the connection still has a
|
||||
* pool, without probing or mutating anything (#4339).
|
||||
*
|
||||
* Liveness events must be confirmed through this, never through `checkConnectionHealth`: the
|
||||
* latter removes unhealthy pools and is the path `ensureConnected` uses to trigger a reconnect.
|
||||
*/
|
||||
export async function connectionIsOpen(connectionId: string): Promise<boolean> {
|
||||
return invokeBackend("connection_is_open", { connectionId });
|
||||
}
|
||||
|
||||
export async function prewarmConnection(connectionId: string, database?: string, catalog?: string, clientSessionId?: string): Promise<void> {
|
||||
return invokeBackend("prewarm_connection", { connectionId, database, catalog, clientSessionId });
|
||||
}
|
||||
@@ -2853,6 +2865,16 @@ export async function subscribePluginEvents(onEvent: (event: PluginEvent) => voi
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to backend connection-liveness messages (#4339).
|
||||
*
|
||||
* The listener receives the message unwrapped; the web transport's SSE handler parses the same
|
||||
* shape, so the store can stay transport-agnostic.
|
||||
*/
|
||||
export async function subscribeConnectionLiveness(onEvent: (event: ConnectionLivenessMessage) => void): Promise<UnlistenFn> {
|
||||
return listen<ConnectionLivenessMessage>("dbx-connection-liveness", (event) => onEvent(event.payload));
|
||||
}
|
||||
|
||||
export async function listJdbcDrivers(): Promise<JdbcDriverInfo[]> {
|
||||
return invoke("list_jdbc_drivers");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user