mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 06:43:59 +00:00
cleanup of not used sessions
This commit is contained in:
@@ -103,6 +103,10 @@ module.exports = {
|
|||||||
if (handleProcessCommunication(message, subprocess)) return;
|
if (handleProcessCommunication(message, subprocess)) return;
|
||||||
this[`handle_${msgtype}`](sesid, message);
|
this[`handle_${msgtype}`](sesid, message);
|
||||||
});
|
});
|
||||||
|
subprocess.on('exit', () => {
|
||||||
|
this.opened = this.opened.filter(x => x.sesid != sesid);
|
||||||
|
});
|
||||||
|
|
||||||
subprocess.send({ msgtype: 'connect', ...connection, database });
|
subprocess.send({ msgtype: 'connect', ...connection, database });
|
||||||
return _.pick(newOpened, ['conid', 'database', 'sesid']);
|
return _.pick(newOpened, ['conid', 'database', 'sesid']);
|
||||||
},
|
},
|
||||||
@@ -165,6 +169,17 @@ module.exports = {
|
|||||||
return { state: 'ok' };
|
return { state: 'ok' };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ping_meta: true,
|
||||||
|
async ping({ sesid }) {
|
||||||
|
const session = this.opened.find(x => x.sesid == sesid);
|
||||||
|
if (!session) {
|
||||||
|
throw new Error('Invalid session');
|
||||||
|
}
|
||||||
|
session.subprocess.send({ msgtype: 'ping' });
|
||||||
|
|
||||||
|
return { state: 'ok' };
|
||||||
|
},
|
||||||
|
|
||||||
// runCommand_meta: true,
|
// runCommand_meta: true,
|
||||||
// async runCommand({ conid, database, sql }) {
|
// async runCommand({ conid, database, sql }) {
|
||||||
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ let systemConnection;
|
|||||||
let storedConnection;
|
let storedConnection;
|
||||||
let afterConnectCallbacks = [];
|
let afterConnectCallbacks = [];
|
||||||
// let currentHandlers = [];
|
// let currentHandlers = [];
|
||||||
|
let lastPing = null;
|
||||||
|
|
||||||
class TableWriter {
|
class TableWriter {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -271,10 +272,15 @@ async function handleExecuteReader({ jslid, sql, fileName }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePing() {
|
||||||
|
lastPing = new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
executeQuery: handleExecuteQuery,
|
executeQuery: handleExecuteQuery,
|
||||||
executeReader: handleExecuteReader,
|
executeReader: handleExecuteReader,
|
||||||
|
ping: handlePing,
|
||||||
// cancel: handleCancel,
|
// cancel: handleCancel,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -285,6 +291,15 @@ async function handleMessage({ msgtype, ...other }) {
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
childProcessChecker();
|
childProcessChecker();
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
const time = new Date().getTime();
|
||||||
|
if (time - lastPing > 30_000) {
|
||||||
|
console.log('Session not alive, exiting');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}, 30_000);
|
||||||
|
|
||||||
process.on('message', async message => {
|
process.on('message', async message => {
|
||||||
if (handleProcessCommunication(message)) return;
|
if (handleProcessCommunication(message)) return;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
||||||
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
|
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
|
||||||
import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte';
|
import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte';
|
||||||
|
import { onDestroy, onMount } from 'svelte';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
export let conid;
|
export let conid;
|
||||||
@@ -102,6 +103,22 @@
|
|||||||
|
|
||||||
$: generatePreview($modelState.value, engine);
|
$: generatePreview($modelState.value, engine);
|
||||||
|
|
||||||
|
let intervalId;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
intervalId = setInterval(() => {
|
||||||
|
if (sessionId) {
|
||||||
|
apiCall('sessions/ping', {
|
||||||
|
sesid: sessionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 15_000);
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
});
|
||||||
|
|
||||||
export function canKill() {
|
export function canKill() {
|
||||||
return !!sessionId;
|
return !!sessionId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext } from 'svelte';
|
import { getContext, onDestroy, onMount } from 'svelte';
|
||||||
import sqlFormatter from 'sql-formatter';
|
import sqlFormatter from 'sql-formatter';
|
||||||
|
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
@@ -100,6 +100,21 @@
|
|||||||
let resultCount;
|
let resultCount;
|
||||||
let errorMessages;
|
let errorMessages;
|
||||||
let domEditor;
|
let domEditor;
|
||||||
|
let intervalId;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
intervalId = setInterval(() => {
|
||||||
|
if (sessionId) {
|
||||||
|
apiCall('sessions/ping', {
|
||||||
|
sesid: sessionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 15_000);
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
});
|
||||||
|
|
||||||
$: connection = useConnectionInfo({ conid });
|
$: connection = useConnectionInfo({ conid });
|
||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver($connection, $extensions);
|
||||||
|
|||||||
Reference in New Issue
Block a user