Browse Source

优化删除定时任务及任务命名

locky 1 year ago
parent
commit
9551b0fc18
1 changed files with 6 additions and 2 deletions
  1. 6 2
      Controller/SensorGateway/SmartSceneController.py

+ 6 - 2
Controller/SensorGateway/SmartSceneController.py

@@ -1316,7 +1316,8 @@ class SmartSceneView(View):
         @return: task_id
         """
         celery_beat_obj = CeleryBeatObj()
-        name = serial_number + '_'
+        # 任务名拼接当前时间戳,防止重复
+        name = '{}_{}_'.format(serial_number, str(int(time.time())))
         kwargs = {
             'device_type': device_type,
             'event_type': event_type,
@@ -1425,7 +1426,10 @@ class SmartSceneView(View):
                     # 存在任务则删除
                     task_id = time_task.get('task_id')
                     if task_id:
-                        celery_beat_obj.del_task(task_id)
+                        try:
+                            celery_beat_obj.del_task(task_id)
+                        except Exception:
+                            continue
 
     @classmethod
     def pause_or_resume_job(cls, scene_data_dict, scene_status, scene_id):