From 0fd5ab02e98e5536a5a2af5d856b4010990d7d29 Mon Sep 17 00:00:00 2001 From: xinwen Date: Thu, 1 Jul 2021 10:42:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20interval=20?= =?UTF-8?q?=E5=91=A8=E6=9C=9F=E4=BB=BB=E5=8A=A1=E4=B8=8D=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/celery/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/ops/celery/utils.py b/apps/ops/celery/utils.py index 959e4c907..c35db0f0e 100644 --- a/apps/ops/celery/utils.py +++ b/apps/ops/celery/utils.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # import json -import os import redis_lock import redis @@ -12,6 +11,7 @@ from django_celery_beat.models import ( PeriodicTask, IntervalSchedule, CrontabSchedule, PeriodicTasks ) +from common.utils.timezone import now from common.utils import get_logger logger = get_logger(__name__) @@ -36,6 +36,8 @@ def create_or_update_celery_periodic_tasks(tasks): for name, detail in tasks.items(): interval = None crontab = None + last_run_at = None + try: IntervalSchedule.objects.all().count() except (ProgrammingError, OperationalError): @@ -50,6 +52,7 @@ def create_or_update_celery_periodic_tasks(tasks): interval = IntervalSchedule.objects.filter(**kwargs).first() if interval is None: interval = IntervalSchedule.objects.create(**kwargs) + last_run_at = now() elif isinstance(detail.get("crontab"), str): try: minute, hour, day, month, week = detail["crontab"].split() @@ -75,7 +78,8 @@ def create_or_update_celery_periodic_tasks(tasks): enabled=detail.get('enabled', True), args=json.dumps(detail.get('args', [])), kwargs=json.dumps(detail.get('kwargs', {})), - description=detail.get('description') or '' + description=detail.get('description') or '', + last_run_at=last_run_at, ) task = PeriodicTask.objects.update_or_create( defaults=defaults, name=name,