Skip to content

Commit

Permalink
执行回调增加落库异常的处理
Browse files Browse the repository at this point in the history
过滤系统信息内的的部分信息展示
  • Loading branch information
hhyo committed Mar 27, 2022
1 parent d41f64c commit 18d1dd3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def authenticate(self):
except:
logger.error('验证用户密码时报错')
logger.error(traceback.format_exc())
return {'status': 1, 'msg': f'服务器错误{traceback.format_exc()}', 'data': ''}
return {'status': 1, 'msg': f'服务异常,请联系管理员处理', 'data': ''}
# 已存在用户, 验证是否在锁期间
# 读取配置文件
lock_count = int(self.sys_config.get('lock_cnt_threshold', 5))
Expand Down
22 changes: 17 additions & 5 deletions sql/utils/execute_sql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: UTF-8 -*-
import logging
import traceback

from django.db import close_old_connections, connection, transaction
from django_redis import get_redis_connection
Expand All @@ -10,6 +12,8 @@
from sql.utils.workflow_audit import Audit
from sql.engines import get_engine

logger = logging.getLogger('default')


def execute(workflow_id, user=None):
"""为延时或异步任务准备的execute, 传入工单ID和执行人信息"""
Expand Down Expand Up @@ -69,11 +73,19 @@ def execute_callback(task):
else:
execute_result = task.result
workflow.status = 'workflow_finish'
# 保存执行结果
workflow.sqlworkflowcontent.execute_result = execute_result.json()
workflow.sqlworkflowcontent.save()
workflow.save()

try:
# 保存执行结果
workflow.sqlworkflowcontent.execute_result = execute_result.json()
workflow.sqlworkflowcontent.save()
workflow.save()
except Exception as e:
logger.error(f'SQL工单回调异常: {workflow_id} {traceback.format_exc()}')
SqlWorkflow.objects.filter(id=workflow_id).update(
finish_time=task.stopped,
status='workflow_exception',
)
workflow.sqlworkflowcontent.execute_result = {f'{e}'}
workflow.sqlworkflowcontent.save()
# 增加工单日志
audit_id = Audit.detail_by_workflow_id(workflow_id=workflow_id,
workflow_type=WorkflowDict.workflow_type['sqlreview']).audit_id
Expand Down
8 changes: 8 additions & 0 deletions sql_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def debug(request):

# 系统配置
sys_config = SysConfig().sys_config
# 敏感信息处理
secret_keys = [
'inception_remote_backup_password',
'ding_app_secret',
'feishu_app_secret',
'mail_smtp_password'
]
sys_config.update({k: "******" for k in secret_keys})

# MySQL信息
cursor = connection.cursor()
Expand Down

0 comments on commit 18d1dd3

Please sign in to comment.