feat: 添加 task 的 verbose_name

pull/9414/head
Aaron3S 2023-02-02 15:57:06 +08:00 committed by Jiangjie.Bai
parent 4c9d16b4c1
commit 1083f5f6f2
6 changed files with 27 additions and 23 deletions

View File

@ -9,6 +9,7 @@ from ops.celery.decorator import (
)
from .models import UserLoginLog, OperateLog, FTPLog
from common.utils import get_log_keep_day
from django.utils.translation import gettext_lazy as _
def clean_login_log_period():
@ -32,8 +33,8 @@ def clean_ftp_log_period():
FTPLog.objects.filter(date_start__lt=expired_day).delete()
@register_as_period_task(interval=3600*24)
@shared_task
@register_as_period_task(interval=3600 * 24)
@shared_task(verbose_name=_('Clean audits log'))
def clean_audits_log_period():
clean_login_log_period()
clean_operation_log_period()

View File

@ -5,9 +5,10 @@ from celery import shared_task
from ops.celery.decorator import register_as_period_task
from django.contrib.sessions.models import Session
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
@register_as_period_task(interval=3600*24)
@shared_task
@register_as_period_task(interval=3600 * 24)
@shared_task(verbose_name=_('Clean expired session'))
def clean_django_sessions():
Session.objects.filter(expire_date__lt=timezone.now()).delete()

View File

@ -8,12 +8,12 @@ from common.sdk.sms.endpoint import SMS
from common.exceptions import JMSException
from common.utils.random import random_string
from common.utils import get_logger
from django.utils.translation import gettext_lazy as _
logger = get_logger(__file__)
@shared_task
@shared_task(verbose_name=_('Send email'))
def send_async(sender):
sender.gen_and_send()

View File

@ -19,12 +19,13 @@ from perms.notifications import (
PermedAssetsWillExpireUserMsg,
AssetPermsWillExpireForOrgAdminMsg,
)
from django.utils.translation import gettext_lazy as _
logger = get_logger(__file__)
@register_as_period_task(interval=settings.PERM_EXPIRED_CHECK_PERIODIC)
@shared_task()
@shared_task(verbose_name=_('Check asset permission expired'))
@atomic()
@tmp_to_root_org()
def check_asset_permission_expired():
@ -36,7 +37,7 @@ def check_asset_permission_expired():
@register_as_period_task(crontab=CRONTAB_AT_AM_TEN)
@shared_task()
@shared_task(verbose_name=_('Send asset permission expired notification'))
@atomic()
@tmp_to_root_org()
def check_asset_permission_will_expired():

View File

@ -21,13 +21,14 @@ from .models import (
Status, Session, Command, Task, AppletHostDeployment
)
from .utils import find_session_replay_local
from django.utils.translation import gettext_lazy as _
CACHE_REFRESH_INTERVAL = 10
RUNNING = False
logger = get_task_logger(__name__)
@shared_task
@shared_task(verbose_name=_('Periodic delete terminal status'))
@register_as_period_task(interval=3600)
@after_app_ready_start
@after_app_shutdown_clean_periodic
@ -36,7 +37,7 @@ def delete_terminal_status_period():
Status.objects.filter(date_created__lt=yesterday).delete()
@shared_task
@shared_task(verbose_name=_('Clean orphan session'))
@register_as_period_task(interval=600)
@after_app_ready_start
@after_app_shutdown_clean_periodic
@ -55,7 +56,7 @@ def clean_orphan_session():
session.save()
@shared_task
@shared_task(verbose_name=_('Periodic clean expired session'))
@register_as_period_task(interval=3600 * 24)
@after_app_ready_start
@after_app_shutdown_clean_periodic
@ -81,7 +82,7 @@ def clean_expired_session_period():
logger.info("Clean session replay done")
@shared_task
@shared_task(verbose_name=_('Upload session replay to external storage'))
def upload_session_replay_to_external_storage(session_id):
logger.info(f'Start upload session to external storage: {session_id}')
session = Session.objects.filter(id=session_id).first()
@ -108,14 +109,14 @@ def upload_session_replay_to_external_storage(session_id):
return
@shared_task
@shared_task(verbose_name=_('Run applet host deployment'))
def run_applet_host_deployment(did):
with tmp_to_builtin_org(system=1):
deployment = AppletHostDeployment.objects.get(id=did)
deployment.start()
@shared_task
@shared_task(verbose_name=_('Install applet'))
def run_applet_host_deployment_install_applet(did, applet_id):
with tmp_to_builtin_org(system=1):
deployment = AppletHostDeployment.objects.get(id=did)

View File

@ -16,12 +16,12 @@ 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
from django.utils.translation import gettext_lazy as _
logger = get_logger(__file__)
@shared_task
@shared_task(verbose_name=_('Check password expired'))
def check_password_expired():
users = User.get_nature_users().filter(source=User.Source.local)
for user in users:
@ -35,7 +35,7 @@ def check_password_expired():
PasswordExpirationReminderMsg(user).publish_async()
@shared_task
@shared_task(verbose_name=_('Periodic check password expired'))
@after_app_ready_start
def check_password_expired_periodic():
tasks = {
@ -49,11 +49,11 @@ def check_password_expired_periodic():
create_or_update_celery_periodic_tasks(tasks)
@shared_task
@shared_task(verbose_name=_('Check user expired'))
def check_user_expired():
date_expired_lt = timezone.now() + timezone.timedelta(days=User.DATE_EXPIRED_WARNING_DAYS)
users = User.get_nature_users()\
.filter(source=User.Source.local)\
users = User.get_nature_users() \
.filter(source=User.Source.local) \
.filter(date_expired__lt=date_expired_lt)
for user in users:
@ -66,7 +66,7 @@ def check_user_expired():
UserExpirationReminderMsg(user).publish_async()
@shared_task
@shared_task(verbose_name=_('Periodic check user expired'))
@after_app_ready_start
def check_user_expired_periodic():
tasks = {
@ -80,7 +80,7 @@ def check_user_expired_periodic():
create_or_update_celery_periodic_tasks(tasks)
@shared_task
@shared_task(verbose_name=_('Import ldap user'))
def import_ldap_user():
logger.info("Start import ldap user task")
util_server = LDAPServerUtil()
@ -101,7 +101,7 @@ def import_ldap_user():
logger.info('Imported {} users successfully'.format(len(users)))
@shared_task
@shared_task(verbose_name=_('Periodic import ldap user'))
@after_app_ready_start
def import_ldap_user_periodic():
if not settings.AUTH_LDAP: