From 51acf6caa0ee441da4a8d0d6d912070776f61f25 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 7 Aug 2023 00:33:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=86=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E7=AD=96=E7=95=A5=E5=B9=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=94=9F=E6=88=90cron=E6=96=87=E6=9C=AC2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- safesite/services.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/safesite/services.py b/safesite/services.py index 5d2d183c..0f0a2b92 100644 --- a/safesite/services.py +++ b/safesite/services.py @@ -2,6 +2,7 @@ import locale from croniter import croniter from cron_descriptor import get_description from safesite.models import MySchedule, GridTaskSet, PeriodicTask +from django.core.exceptions import ObjectDoesNotExist period_dict = { "days": "天", "hours": "小时", @@ -33,10 +34,14 @@ def correct_myschedule(): item.name = get_chinese_description(typeset, {'every': interval.every, 'period': interval.period}) item.save() elif typeset == 'crontab': - crontab = item.crontab - item.name = get_chinese_description(typeset, - {"minute": crontab.minute, "hour": crontab.hour, "day_of_month": crontab.day_of_month, - "month_of_year": crontab.month_of_year, "day_of_week": crontab.day_of_week}) - if item.name == '': - crontab.delete() + try: + crontab = item.crontab + item.name = get_chinese_description(typeset, + {"minute": crontab.minute, "hour": crontab.hour, "day_of_month": crontab.day_of_month, + "month_of_year": crontab.month_of_year, "day_of_week": crontab.day_of_week}) + if item.name == '': + crontab.delete() + item.delete() + except ObjectDoesNotExist: + GridTaskSet.objects.filter(myschedule=item).delete() item.delete() \ No newline at end of file