peng 1 жил өмнө
parent
commit
682ae37c06

+ 1 - 1
Controller/SensorGateway/SmartSwitchController.py

@@ -468,8 +468,8 @@ class SmartSwitchView(View):
                           'actions': actions,
                           'timerStatus': timer_status}
             with transaction.atomic():
+                celery_obj.del_task(task_id)
                 if is_edit:
-                    celery_obj.del_task(task_id)
                     if not timer_status:
                         return response.json(444, {'param': 'timerStatus'})
                     timer_status = int(timer_status)

+ 2 - 12
Object/CeleryBeatObject.py

@@ -62,18 +62,8 @@ class CeleryBeatObj:
             time_stamp = CommonService.convert_to_timestamp(timezone_offset, time_string)
         # 时间戳转为东八区的时间字符串
         clocked_time = CommonService.get_date_from_timestamp(time_stamp, 8)
-        periodic_task = PeriodicTask.objects.filter(name=name)
-        if periodic_task.exists():
-            periodic_task_qs = periodic_task[0]
-            clocked_id = periodic_task_qs.clocked_id
-            ClockedSchedule.objects.filter(id=clocked_id).update(clocked_time=clocked_time)
-            periodic_task_qs.task = task
-            periodic_task_qs.args = args
-            periodic_task_qs.kwargs = kwargs
-            periodic_task_qs.save()
-        else:
-            schedule, _ = ClockedSchedule.objects.get_or_create(clocked_time=clocked_time)
-            PeriodicTask.objects.create(clocked=schedule, one_off=True, name=name, task=task, args=args, kwargs=kwargs)
+        schedule, _ = ClockedSchedule.objects.get_or_create(clocked_time=clocked_time)
+        PeriodicTask.objects.create(clocked=schedule, one_off=True, name=name, task=task, args=args, kwargs=kwargs)
 
     @staticmethod
     def creat_crontab_task(