From 5e9c15c4a52add7069d20ba074e4ee9594cd2116 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 28 Aug 2025 16:08:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=BB=A5=E6=A0=87=E8=AE=B0mtask=E4=B8=BA?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/pm/tasks.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 apps/pm/tasks.py diff --git a/apps/pm/tasks.py b/apps/pm/tasks.py new file mode 100644 index 00000000..95a9533f --- /dev/null +++ b/apps/pm/tasks.py @@ -0,0 +1,24 @@ +# Create your tasks here +from __future__ import absolute_import, unicode_literals +from apps.pm.models import Mtask, Utask +from apps.utils.tasks import CustomTask +from celery import shared_task +from datetime import datetime, timedelta +from django.db.models import F +from apps.pm.services import PmService + +@shared_task(base=CustomTask) +def complete_mtask(): + """ + 将2天前未提交的任务且数量已达标的任务标记为已完成 + """ + now = datetime.now().date() + mtasks = Mtask.objects.filter(state=Mtask.MTASK_ASSGINED, + end_date__lte=now-timedelta(days=2), + count_ok__gte=F('count')) + mtasks.update(state=Mtask.MTASK_SUBMIT) + + utasks = Utask.objects.filter(id__in=mtasks.values_list("utask__id", flat=True)) + + for utask in utasks: + PmService.utask_submit(utask=utask, raise_e=False) \ No newline at end of file