Browse Source

优化定时器

peng 1 year ago
parent
commit
6985020079
1 changed files with 4 additions and 17 deletions
  1. 4 17
      Controller/SensorGateway/SmartSwitchController.py

+ 4 - 17
Controller/SensorGateway/SmartSwitchController.py

@@ -287,13 +287,9 @@ class SmartSwitchView(View):
                         **chronopher_data)
                     if not update_flag:
                         return response.json(173)
-                    redis_obj = RedisObject()
                     apscheduler_obj.del_job('switchchronopher_{}'.format(chronopher_id))
                     apscheduler_obj.del_job('switchchronopher_{}_1'.format(chronopher_id))
                     apscheduler_obj.del_job('switchchronopher_{}_2'.format(chronopher_id))
-                    redis_obj.del_data('switchchronopher_{}'.format(chronopher_id))
-                    redis_obj.del_data('switchchronopher_{}_1'.format(chronopher_id))
-                    redis_obj.del_data('switchchronopher_{}_2'.format(chronopher_id))
                 else:
                     switch_qs = SwitchChronopher.objects.create(**chronopher_data)
                     chronopher_id = switch_qs.id
@@ -373,14 +369,10 @@ class SmartSwitchView(View):
             delete_flag = SwitchChronopher.objects.filter(device_id=device_id, id=chronopher_id).delete()
             if not delete_flag[0]:
                 return response.json(173)
-            redis_obj = RedisObject()
             apscheduler_obj = ApschedulerObject()
             apscheduler_obj.del_job('switchchronopher_{}'.format(chronopher_id))  # 删除定时任务
             apscheduler_obj.del_job('switchchronopher_{}_1'.format(chronopher_id))
             apscheduler_obj.del_job('switchchronopher_{}_2'.format(chronopher_id))
-            redis_obj.del_data('switchchronopher_{}'.format(chronopher_id))
-            redis_obj.del_data('switchchronopher_{}_1'.format(chronopher_id))
-            redis_obj.del_data('switchchronopher_{}_2'.format(chronopher_id))
             return response.json(0)
         except Exception as e:
             print(e)
@@ -396,15 +388,10 @@ class SmartSwitchView(View):
         @param task_id: 任务id
         @return: response
         """
-        redis_obj = RedisObject()
-        flag = redis_obj.get_data(task_id)
-        if not flag:
-            result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
-            LOGGER.info('定时发送mqtt结果:{},参数:{},{},{},{},{},线程:{},进程:{}'.format(result, serial_number, topic_name, msg,
-                                                                             int(time.time()), task_id,
-                                                                             threading.get_ident(),
-                                                                             os.getpid()))
-            redis_obj.set_ex_data(task_id, 1, 5)
+        result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
+        LOGGER.info('定时发送mqtt结果:{},参数:{},{},{},{},{},线程:{},进程:{}'.format(result, serial_number, topic_name, msg,
+                                                                         int(time.time()), task_id,
+                                                                         threading.get_ident(), os.getpid()))
 
     @staticmethod
     def create_log(request_dict, response):