mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
connections pinger
This commit is contained in:
parent
7a5bcc62c8
commit
28c1421294
@ -28,6 +28,7 @@
|
||||
"uuid": "^3.4.0",
|
||||
"json-stable-stringify": "^1.0.1",
|
||||
"localforage": "^1.9.0",
|
||||
"dbgate-types": "^3.9.5",
|
||||
"lodash": "^4.17.15"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -11,7 +11,7 @@
|
||||
export let extInfo;
|
||||
</script>
|
||||
|
||||
<div class="main" class:isBold draggable>
|
||||
<div class="main" class:isBold draggable on:click>
|
||||
{prefix || ''}
|
||||
{#if isBusy}
|
||||
<FontIcon icon="icon loading" />
|
||||
|
@ -1,9 +1,28 @@
|
||||
<script lang="ts">
|
||||
import _ from 'lodash';
|
||||
import AppObjectCore from './AppObjectCore.svelte';
|
||||
import { currentDatabase, openedConnections } from '../stores';
|
||||
|
||||
export let commonProps;
|
||||
export let data;
|
||||
|
||||
function getStatusIcon(opened) {
|
||||
const { _id, status } = data;
|
||||
if (opened.includes(_id)) {
|
||||
if (!status) return 'icon loading';
|
||||
if (status.name == 'pending') return 'icon loading';
|
||||
if (status.name == 'ok') return 'img ok';
|
||||
return 'img error';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<AppObjectCore {...commonProps} title={data.displayName || data.server} icon="img server" />
|
||||
<AppObjectCore
|
||||
{...commonProps}
|
||||
title={data.displayName || data.server}
|
||||
icon="img server"
|
||||
isBold={_.get($currentDatabase, 'connection._id') == data._id}
|
||||
statusIcon={getStatusIcon($openedConnections)}
|
||||
statusTitle={data.status && data.status.name == 'error' ? data.status.message : null}
|
||||
on:click={() => ($openedConnections = _.uniq([...$openedConnections, data._id]))}
|
||||
/>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import App from './App.svelte';
|
||||
import './utility/connectionsPinger';
|
||||
|
||||
const app = new App({
|
||||
target: document.body,
|
||||
|
29
packages/web/src/utility/connectionsPinger.js
Normal file
29
packages/web/src/utility/connectionsPinger.js
Normal file
@ -0,0 +1,29 @@
|
||||
import _ from 'lodash';
|
||||
import { openedConnections, currentDatabase } from '../stores';
|
||||
import axios from './axios';
|
||||
|
||||
const doServerPing = value => {
|
||||
axios.post('server-connections/ping', { connections: value });
|
||||
};
|
||||
|
||||
const doDatabasePing = value => {
|
||||
const database = _.get(value, 'name');
|
||||
const conid = _.get(value, 'connection._id');
|
||||
if (conid && database) {
|
||||
axios.post('database-connections/ping', { conid, database });
|
||||
}
|
||||
};
|
||||
|
||||
let openedConnectionsHandle = null;
|
||||
openedConnections.subscribe(value => {
|
||||
doServerPing(value);
|
||||
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
|
||||
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000);
|
||||
});
|
||||
|
||||
let currentDatabaseHandle = null;
|
||||
currentDatabase.subscribe(value => {
|
||||
doDatabasePing(value);
|
||||
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
|
||||
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000);
|
||||
});
|
@ -5,19 +5,20 @@ import stableStringify from 'json-stable-stringify';
|
||||
import { cacheClean } from './cache';
|
||||
import socket from './socket';
|
||||
import getAsArray from './getAsArray';
|
||||
import { DatabaseInfo } from 'dbgate-types';
|
||||
|
||||
const databaseInfoLoader = ({ conid, database }) => ({
|
||||
url: 'database-connections/structure',
|
||||
params: { conid, database },
|
||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||
transform: db => {
|
||||
transform: (db: DatabaseInfo) => {
|
||||
const allForeignKeys = _.flatten(db.tables.map(x => x.foreignKeys));
|
||||
return {
|
||||
...db,
|
||||
tables: db.tables.map(table => ({
|
||||
...table,
|
||||
dependencies: allForeignKeys.filter(
|
||||
(x: any) => x.refSchemaName == table.schemaName && x.refTableName == table.pureName
|
||||
x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName
|
||||
),
|
||||
})),
|
||||
};
|
||||
|
@ -2,5 +2,14 @@
|
||||
// "extends": "@tsconfig/svelte/tsconfig.json",
|
||||
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules/*", "public/*"]
|
||||
}
|
||||
"exclude": ["node_modules/*", "public/*"],
|
||||
|
||||
"compilerOptions": {
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"noImplicitAny": false,
|
||||
"strictNullChecks": false,
|
||||
"strict": false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user