mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-05 17:30:30 +00:00
fix: merge_delay_run 偶尔会出现 (2006, MySQL server has gone away 的报错)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from contextlib import contextmanager
|
||||
|
||||
from django.db import connections
|
||||
from django.db import connections, transaction
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
from common.utils import get_logger, signer, crypto
|
||||
@@ -58,6 +58,17 @@ def safe_db_connection():
|
||||
close_old_connections()
|
||||
|
||||
|
||||
@contextmanager
|
||||
def open_db_connection(alias='default'):
|
||||
connection = transaction.get_connection(alias)
|
||||
try:
|
||||
connection.connect()
|
||||
with transaction.atomic():
|
||||
yield connection
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
||||
class Encryptor:
|
||||
def __init__(self, value):
|
||||
self.value = force_str(value)
|
||||
|
Reference in New Issue
Block a user