fix: settings 订阅不稳定

pull/5953/head
xinwen 2021-04-13 18:33:00 +08:00 committed by 老广
parent ce6b9de07c
commit 9944474ba0
1 changed files with 3 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import threading
from django.dispatch import receiver
from django.db.models.signals import post_save, pre_save
from django.utils.functional import LazyObject
from django.db import close_old_connections
from jumpserver.utils import current_request
from common.decorator import on_transaction_commit
@ -75,6 +76,7 @@ def subscribe_settings_change(sender, **kwargs):
try:
sub = setting_pub_sub.subscribe()
for msg in sub.listen():
close_old_connections()
if msg["type"] != "message":
continue
item = msg['data'].decode()
@ -82,6 +84,7 @@ def subscribe_settings_change(sender, **kwargs):
Setting.refresh_item(item)
except Exception as e:
logger.exception(f'subscribe_settings_change: {e}')
close_old_connections()
Setting.refresh_all_settings()
t = threading.Thread(target=keep_subscribe)