From 15f6d5c9c0103eab62613214181b2087945d511c Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 7 Dec 2017 13:28:11 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20terminal=20tasks=20main()=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=EF=BC=8C=E5=8F=AF=E8=83=BD=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=98=E4=B8=8D=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/tasks.py | 21 ++++++++++++++------- utils/clean_migrations.sh | 9 +++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/terminal/tasks.py b/apps/terminal/tasks.py index 47b0748af..c286b1db7 100644 --- a/apps/terminal/tasks.py +++ b/apps/terminal/tasks.py @@ -5,10 +5,12 @@ import time from celery import shared_task from django.core.cache import cache +from django.db.utils import ProgrammingError from .models import Session + ASSETS_CACHE_KEY = "terminal__session__assets" USERS_CACHE_KEY = "terminal__session__users" SYSTEM_USER_CACHE_KEY = "terminal__session__system_users" @@ -36,14 +38,18 @@ def get_session_system_user_list(): def set_cache(): while True: - assets = get_session_asset_list() - users = get_session_user_list() - system_users = get_session_system_user_list() + try: + assets = get_session_asset_list() + users = get_session_user_list() + system_users = get_session_system_user_list() - cache.set(ASSETS_CACHE_KEY, assets) - cache.set(USERS_CACHE_KEY, users) - cache.set(SYSTEM_USER_CACHE_KEY, system_users) - time.sleep(10) + cache.set(ASSETS_CACHE_KEY, assets) + cache.set(USERS_CACHE_KEY, users) + cache.set(SYSTEM_USER_CACHE_KEY, system_users) + except ProgrammingError: + pass + finally: + time.sleep(10) def main(): @@ -59,4 +65,5 @@ def main(): t.start() RUNNING = True +# Todo: 不能migrations了 main() diff --git a/utils/clean_migrations.sh b/utils/clean_migrations.sh index b5493dc0d..433e50276 100755 --- a/utils/clean_migrations.sh +++ b/utils/clean_migrations.sh @@ -1,6 +1,11 @@ #!/bin/bash # -for app in users assets perms audits ops applications;do - rm -f ../apps/$app/migrations/00* +cd ../apps + +for d in $(ls);do + if [ -d $d ] && [ -d $d/migrations ];then + rm -f $d/migrations/00* + fi done +