فهرست منبع

发送mqtt时使用redis锁

peng 1 سال پیش
والد
کامیت
a74be35e55
1فایلهای تغییر یافته به همراه2 افزوده شده و 1 حذف شده
  1. 2 1
      Controller/SensorGateway/SmartSwitchController.py

+ 2 - 1
Controller/SensorGateway/SmartSwitchController.py

@@ -365,15 +365,16 @@ class SmartSwitchView(View):
         msg['implementTime'] = now_time
         redis_obj = RedisObject()
         is_lock = redis_obj.CONN.setnx(task_id + 'do_notify', 1)
-        redis_obj.CONN.expire(task_id + 'do_notify', 60)
         if not is_lock:
             LOGGER.info('定时发送mqtt结果:{},参数:{},{},{},{},{},线程:{},进程:{}'.format(False, serial_number, topic_name, msg,
                                                                              now_time, task_id,
                                                                              threading.get_ident(), os.getpid()))
+            return
         result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
         LOGGER.info('定时发送mqtt结果:{},参数:{},{},{},{},{},线程:{},进程:{}'.format(result, serial_number, topic_name, msg,
                                                                          now_time, task_id,
                                                                          threading.get_ident(), os.getpid()))
+        redis_obj.CONN.expire(task_id + 'do_notify', 60)
         redis_obj.del_data(key=task_id + 'do_notify')
 
     @staticmethod