mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed the server heartbeat logging issue when server is removed. #5567
This commit is contained in:
@@ -15,7 +15,7 @@ import Notify, {initializeModalProvider, initializeNotifier} from '../../../stat
|
||||
import { checkMasterPassword } from '../../../static/js/Dialogs/index';
|
||||
import { pgHandleItemError } from '../../../static/js/utils';
|
||||
import { Search } from './quick_search/trigger_search';
|
||||
import { send_heartbeat } from './heartbeat';
|
||||
import { send_heartbeat, stop_heartbeat } from './heartbeat';
|
||||
|
||||
define('pgadmin.browser', [
|
||||
'sources/gettext', 'sources/url_for', 'require', 'jquery',
|
||||
@@ -586,6 +586,10 @@ define('pgadmin.browser', [
|
||||
'pgadmin:server:connected', send_heartbeat.bind(obj)
|
||||
);
|
||||
|
||||
obj.Events.on(
|
||||
'pgadmin:server:disconnect', stop_heartbeat.bind(obj)
|
||||
);
|
||||
|
||||
obj.set_master_password('');
|
||||
obj.check_corrupted_db_file();
|
||||
obj.Events.on('pgadmin:browser:tree:add', obj.onAddTreeNode.bind(obj));
|
||||
|
||||
@@ -16,16 +16,32 @@ import pgAdmin from 'sources/pgadmin';
|
||||
const axiosApi = getApiInstance();
|
||||
let HEARTBEAT_TIMEOUT = pgAdmin.heartbeat_timeout * 1000;
|
||||
|
||||
export function send_heartbeat(_server_id) {
|
||||
export function send_heartbeat(_server_id, _item) {
|
||||
|
||||
// Send heartbeat to the server every 30 seconds
|
||||
setInterval(function() {
|
||||
axiosApi.post(url_for('misc.heartbeat'), {'sid': _server_id})
|
||||
.then(() => {
|
||||
// pass
|
||||
_item.heartbeat = setInterval(function() {
|
||||
axiosApi.post(url_for('misc.log_heartbeat'), {'sid': _server_id})
|
||||
.then((data) => {
|
||||
if (data.status !== 200) {
|
||||
stop_heartbeat(_item);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
Notifier.error(gettext(`pgAdmin server not responding, try to login again: ${error.message || error.response.data.errormsg}`));
|
||||
if (error && error.message == 'Network Error') {
|
||||
Notifier.error(gettext(`pgAdmin server not responding, try to login again: ${error.message || error.response.data.errormsg}`));
|
||||
} else {
|
||||
Notifier.error(gettext(`Server heartbeat logging error: ${error.message || error.response.data.errormsg}`));
|
||||
}
|
||||
stop_heartbeat(_item);
|
||||
});
|
||||
|
||||
}, HEARTBEAT_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
export function stop_heartbeat(_obj) {
|
||||
let _item = _obj.item || _obj,
|
||||
_id = _item.getMetadata('data')._id;
|
||||
clearInterval(_item.heartbeat);
|
||||
axiosApi.post(url_for('misc.stop_heartbeat'), {'sid': _id});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user