mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
1) Fixed an issue where the process watcher dialog throws an error for
the database server which is already removed. Fixes #5985 2) Fixed cognitive complexity reported by SonarQube.
This commit is contained in:
committed by
Akshay Joshi
parent
a026f339c3
commit
be386e77f2
@@ -23,6 +23,7 @@ import logging
|
||||
|
||||
from pgadmin.utils import u_encode, file_quote, fs_encoding, \
|
||||
get_complete_file_path, get_storage_directory, IS_WIN
|
||||
from pgadmin.browser.server_groups.servers.utils import does_server_exists
|
||||
|
||||
import pytz
|
||||
from dateutil import parser
|
||||
@@ -68,9 +69,9 @@ class IProcessDesc(object, metaclass=ABCMeta):
|
||||
try:
|
||||
# check if file name is encoded with UTF-8
|
||||
file = self.bfile.decode('utf-8')
|
||||
except Exception as e:
|
||||
str(e)
|
||||
except Exception:
|
||||
# do nothing if bfile is not encoded.
|
||||
pass
|
||||
|
||||
path = get_complete_file_path(file)
|
||||
path = file if path is None else path
|
||||
@@ -87,14 +88,7 @@ class IProcessDesc(object, metaclass=ABCMeta):
|
||||
else:
|
||||
last_dir = file
|
||||
|
||||
if IS_WIN:
|
||||
if '\\' in last_dir:
|
||||
if len(last_dir) == 1:
|
||||
last_dir = last_dir.replace('\\', '\\\\')
|
||||
else:
|
||||
last_dir = last_dir.replace('\\', '/')
|
||||
else:
|
||||
last_dir = last_dir.replace('\\', '/')
|
||||
last_dir = replace_path_for_win(last_dir)
|
||||
|
||||
return None if hasattr(self, 'is_import') and self.is_import \
|
||||
else last_dir
|
||||
@@ -102,6 +96,16 @@ class IProcessDesc(object, metaclass=ABCMeta):
|
||||
return None
|
||||
|
||||
|
||||
def replace_path_for_win(last_dir=None):
|
||||
if IS_WIN:
|
||||
if '\\' in last_dir and len(last_dir) == 1:
|
||||
last_dir = last_dir.replace('\\', '\\\\')
|
||||
else:
|
||||
last_dir = last_dir.replace('\\', '/')
|
||||
|
||||
return last_dir
|
||||
|
||||
|
||||
class BatchProcess(object):
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
@@ -625,6 +629,9 @@ class BatchProcess(object):
|
||||
):
|
||||
continue
|
||||
|
||||
if BatchProcess._operate_orphan_process(p):
|
||||
continue
|
||||
|
||||
execution_time = None
|
||||
|
||||
stime = parser.parse(p.start_time)
|
||||
@@ -654,6 +661,29 @@ class BatchProcess(object):
|
||||
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def _operate_orphan_process(p):
|
||||
|
||||
if p and p.desc:
|
||||
desc = loads(p.desc)
|
||||
if does_server_exists(desc.sid, current_user.id) is False:
|
||||
current_app.logger.warning(
|
||||
_("Server with id '{0}' is either removed or does "
|
||||
"not exists for the background process "
|
||||
"'{1}'").format(desc.sid, p.pid)
|
||||
)
|
||||
try:
|
||||
BatchProcess.acknowledge(p.pid)
|
||||
except LookupError as lerr:
|
||||
current_app.logger.warning(
|
||||
_("Status for the background process '{0}' could "
|
||||
"not be loaded.").format(p.pid)
|
||||
)
|
||||
current_app.logger.exception(lerr)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def total_seconds(dt):
|
||||
return round(dt.total_seconds(), 2)
|
||||
|
Reference in New Issue
Block a user