mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 16:13:58 +00:00
feat: autorefresh processes, refresh processes w/o displaying loader
This commit is contained in:
@@ -274,6 +274,20 @@ module.exports = {
|
|||||||
return this.loadDataCore('serverSummary', { conid });
|
return this.loadDataCore('serverSummary', { conid });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
listDatabaseProcesses_meta: true,
|
||||||
|
async listDatabaseProcesses(ctx, req) {
|
||||||
|
const { conid } = ctx;
|
||||||
|
testConnectionPermission(conid, req);
|
||||||
|
|
||||||
|
const opened = await this.ensureOpened(conid);
|
||||||
|
if (!opened) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (opened.connection.isReadOnly) return false;
|
||||||
|
|
||||||
|
return this.sendRequest(opened, { msgtype: 'listDatabaseProcesses' });
|
||||||
|
},
|
||||||
|
|
||||||
killDatabaseProcess_meta: true,
|
killDatabaseProcess_meta: true,
|
||||||
async killDatabaseProcess(ctx, req) {
|
async killDatabaseProcess(ctx, req) {
|
||||||
const { conid, pid } = ctx;
|
const { conid, pid } = ctx;
|
||||||
|
|||||||
@@ -158,6 +158,18 @@ async function handleKillDatabaseProccess({ msgid, pid }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleListDatabaseProcesses({ msgid }) {
|
||||||
|
await waitConnected();
|
||||||
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await driver.listProcesses(dbhan);
|
||||||
|
process.send({ msgtype: 'response', msgid, result });
|
||||||
|
} catch (err) {
|
||||||
|
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSummaryCommand({ msgid, command, row }) {
|
async function handleSummaryCommand({ msgid, command, row }) {
|
||||||
return handleDriverDataCore(msgid, driver => driver.summaryCommand(dbhan, command, row));
|
return handleDriverDataCore(msgid, driver => driver.summaryCommand(dbhan, command, row));
|
||||||
}
|
}
|
||||||
@@ -167,6 +179,7 @@ const messageHandlers = {
|
|||||||
ping: handlePing,
|
ping: handlePing,
|
||||||
serverSummary: handleServerSummary,
|
serverSummary: handleServerSummary,
|
||||||
killDatabaseProcess: handleKillDatabaseProccess,
|
killDatabaseProcess: handleKillDatabaseProccess,
|
||||||
|
listDatabaseProcesses: handleListDatabaseProcesses,
|
||||||
summaryCommand: handleSummaryCommand,
|
summaryCommand: handleSummaryCommand,
|
||||||
createDatabase: props => handleDatabaseOp('createDatabase', props),
|
createDatabase: props => handleDatabaseOp('createDatabase', props),
|
||||||
dropDatabase: props => handleDatabaseOp('dropDatabase', props),
|
dropDatabase: props => handleDatabaseOp('dropDatabase', props),
|
||||||
|
|||||||
@@ -4,21 +4,26 @@
|
|||||||
import { _t } from '../translations';
|
import { _t } from '../translations';
|
||||||
import CtaButton from '../buttons/CtaButton.svelte';
|
import CtaButton from '../buttons/CtaButton.svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
import runCommand from '../commands/runCommand';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let processes: DatabaseProcess[] = [];
|
export let processes: DatabaseProcess[] = [];
|
||||||
|
export let refreshInterval: number = 1000;
|
||||||
|
|
||||||
|
let internalProcesses = [...processes];
|
||||||
|
|
||||||
|
async function refreshProcesses() {
|
||||||
|
const data = await apiCall('server-connections/list-database-processes', { conid });
|
||||||
|
internalProcesses = data.result;
|
||||||
|
}
|
||||||
|
|
||||||
async function killProcess(processId: number) {
|
async function killProcess(processId: number) {
|
||||||
// TODO: Implement kill process functionality
|
|
||||||
console.log('Kill process:', processId);
|
|
||||||
|
|
||||||
await apiCall('server-connections/kill-database-process', {
|
await apiCall('server-connections/kill-database-process', {
|
||||||
pid: processId,
|
pid: processId,
|
||||||
conid,
|
conid,
|
||||||
});
|
});
|
||||||
|
|
||||||
runCommand('serverSummary.refresh');
|
refreshProcesses();
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatRunningTime(seconds: number): string {
|
function formatRunningTime(seconds: number): string {
|
||||||
@@ -27,11 +32,17 @@
|
|||||||
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
|
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
|
||||||
return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
|
return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
const intervalId = setInterval(() => refreshProcesses(), refreshInterval);
|
||||||
|
|
||||||
|
return () => clearInterval(intervalId);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<TableControl
|
<TableControl
|
||||||
rows={processes}
|
rows={internalProcesses}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: 'Process ID', fieldName: 'processId', slot: 1 },
|
{ header: 'Process ID', fieldName: 'processId', slot: 1 },
|
||||||
{ header: 'Connection ID', fieldName: 'connectionId' },
|
{ header: 'Connection ID', fieldName: 'connectionId' },
|
||||||
|
|||||||
Reference in New Issue
Block a user