From 145814f1e8b39d4933ede8f1ed8235ac3544c2eb Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Mon, 10 Oct 2022 16:31:45 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=BB=9F=E4=B8=80=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9A=84crontab=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F,=20=E5=AF=B9=E4=BA=8E=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=89=A7=E8=A1=8C=E7=9A=84=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E6=B8=85=E6=99=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/tasks/nodes_amount.py | 4 +++- apps/common/const/crontab.py | 5 +++++ apps/perms/tasks.py | 3 ++- apps/users/tasks.py | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 apps/common/const/crontab.py diff --git a/apps/assets/tasks/nodes_amount.py b/apps/assets/tasks/nodes_amount.py index 2f8f0592d..c6ad2e8ba 100644 --- a/apps/assets/tasks/nodes_amount.py +++ b/apps/assets/tasks/nodes_amount.py @@ -8,6 +8,8 @@ from assets.utils import check_node_assets_amount from common.utils.lock import AcquireFailed from common.utils import get_logger +from common.const.crontab import CRONTAB_AT_AM_TWO + logger = get_logger(__file__) @@ -29,7 +31,7 @@ def check_node_assets_amount_task(org_id=None): logger.error(error) -@register_as_period_task(crontab='0 2 * * *') +@register_as_period_task(crontab=CRONTAB_AT_AM_TWO) @shared_task def check_node_assets_amount_period_task(): check_node_assets_amount_task() diff --git a/apps/common/const/crontab.py b/apps/common/const/crontab.py new file mode 100644 index 000000000..bd9809176 --- /dev/null +++ b/apps/common/const/crontab.py @@ -0,0 +1,5 @@ + +CRONTAB_AT_AM_TWO = '0 14 * * *' +CRONTAB_AT_AM_TEN = '0 10 * * *' +CRONTAB_AT_PM_TWO = '0 2 * * *' + diff --git a/apps/perms/tasks.py b/apps/perms/tasks.py index 30c9600d3..564e5657e 100644 --- a/apps/perms/tasks.py +++ b/apps/perms/tasks.py @@ -10,6 +10,7 @@ from celery import shared_task from orgs.utils import tmp_to_root_org from common.utils import get_logger from common.utils.timezone import local_now, dt_formatter, dt_parser +from common.const.crontab import CRONTAB_AT_AM_TEN from ops.celery.decorator import register_as_period_task from perms.notifications import ( PermedAssetsWillExpireUserMsg, AssetPermsWillExpireForOrgAdminMsg, @@ -54,7 +55,7 @@ def check_asset_permission_expired(): UserGrantedTreeRefreshController.add_need_refresh_by_asset_perm_ids_cross_orgs(asset_perm_ids) -@register_as_period_task(crontab='0 10 * * *') +@register_as_period_task(crontab=CRONTAB_AT_AM_TEN) @shared_task() @atomic() @tmp_to_root_org() diff --git a/apps/users/tasks.py b/apps/users/tasks.py index ea6426aa4..cddf0d2ec 100644 --- a/apps/users/tasks.py +++ b/apps/users/tasks.py @@ -15,6 +15,7 @@ from orgs.models import Organization from .models import User from users.notifications import UserExpirationReminderMsg from settings.utils import LDAPServerUtil, LDAPImportUtil +from common.const.crontab import CRONTAB_AT_AM_TEN, CRONTAB_AT_PM_TWO logger = get_logger(__file__) @@ -41,7 +42,7 @@ def check_password_expired_periodic(): 'check_password_expired_periodic': { 'task': check_password_expired.name, 'interval': None, - 'crontab': '0 10 * * *', + 'crontab': CRONTAB_AT_AM_TEN, 'enabled': True, } } @@ -72,7 +73,7 @@ def check_user_expired_periodic(): 'check_user_expired_periodic': { 'task': check_user_expired.name, 'interval': None, - 'crontab': '0 14 * * *', + 'crontab': CRONTAB_AT_PM_TWO, 'enabled': True, } }