yzk_wechat_event/apps/warning/tasks.py

27 lines
814 B
Python
Raw Normal View History

2023-12-15 17:42:32 +08:00
from datetime import datetime
from celery import shared_task
from django.db.models import Q
from apps.warning.models import WarningLog, WarningLogStatusChoices
import logging
from apps.warning.utils.alarm import alarm_by_warning_log
logger = logging.getLogger('apps')
# @shared_task(name='warning_log')
# def warning_log():
# warning_logs = WarningLog.objects.filter(
# Q(status=WarningLogStatusChoices.CREATED) | Q(status=WarningLogStatusChoices.WARNED_AND_NEED_WARN))[:1000]
# for wl in warning_logs:
# success = alarm_by_warning_log(wl)
# if not success:
# continue
# if wl.status == WarningLogStatusChoices.CREATED:
# wl.latest_warning_time = datetime.now()
# wl.status = WarningLogStatusChoices.CLOSED
# wl.save()