Bläddra i källkod

update expire

lang 4 år sedan
förälder
incheckning
52a4497d60
2 ändrade filer med 31 tillägg och 20 borttagningar
  1. 29 19
      controller/deviceStatus.py
  2. 2 1
      controller/index.py

+ 29 - 19
controller/deviceStatus.py

@@ -275,8 +275,8 @@ class deviceStatus(TemplateView):
         play_url = "http://rtsp.zositech.org:10008/api/v1/players"
         push_url = "http://rtsp.zositech.org:10008/api/v1/pushers"
         try:
-            queryPlay = requests.get(url=play_url, timeout=5)
-            qplay = queryPlay.json()
+            # queryPlay = requests.get(url=play_url, timeout=5)
+            # qplay = queryPlay.json()
 
             queryPush = requests.get(url=push_url, timeout=5)
             qpush = queryPush.json()
@@ -285,10 +285,10 @@ class deviceStatus(TemplateView):
         else:
             # response.json(103, res=list(qplay))
             #正在拉流的ID
-            play_rows = qplay['rows']
-            play_paths = []
-            for val in play_rows:
-                play_paths.append(val['path'])
+            # play_rows = qplay['rows']
+            # play_paths = []
+            # for val in play_rows:
+            #     play_paths.append(val['path'])
 
             #正在推流的ID
             push_rows = qpush['rows']
@@ -296,22 +296,32 @@ class deviceStatus(TemplateView):
             for val in push_rows:
                 startAt = self.str_to_timestamp(val['startAt'])
                 run_time = int(time.time()) - int(startAt)
-                if run_time > 5*60:
+                if run_time > 1*60:
                     push_paths.append(val['path'])
             send_flag = False
             #正在推流但是没有拉流的推流通知设备断掉
+            # for push_path in push_paths:
+            #     if push_path not in play_paths:
+            #         path_list = push_path.split('/')
+            #         has_rtsp_url = UidRtspModel.objects.filter(rtsp_url=path_list[-1]).values('uid','password')
+            #         # has_rtsp_url = UidRtspModel.objects.filter(rtsp_url='RFJrWk9OVVJPUVRnM1IxaFNXazFFUXpFeE1VRT1U').values('uid')
+            #         if has_rtsp_url.exists():
+            #             send_flag = self.runSendStop(has_rtsp_url[0]['uid'], has_rtsp_url[0]['password'], push_path)
+            # if send_flag:
+            #     return JsonResponse({'res':'success'})
+            # else:
+            #     return JsonResponse({'res':'fail'})
+
+            success = 0
             for push_path in push_paths:
-                if push_path not in play_paths:
-                    path_list = push_path.split('/')
-                    has_rtsp_url = UidRtspModel.objects.filter(rtsp_url=path_list[-1]).values('uid','password')
-                    # has_rtsp_url = UidRtspModel.objects.filter(rtsp_url='RFJrWk9OVVJPUVRnM1IxaFNXazFFUXpFeE1VRT1U').values('uid')
-                    if has_rtsp_url.exists():
-                        send_flag = self.runSendStop(has_rtsp_url[0]['uid'], has_rtsp_url[0]['password'], push_path)
-            if send_flag:
-                return JsonResponse({'res':'success'})
-            else:
-                return JsonResponse({'res':'fail'})
-
+                path_list = push_path.split('/')
+                has_rtsp_url = UidRtspModel.objects.filter(rtsp_url=path_list[-1]).values('uid','password')
+                # has_rtsp_url = UidRtspModel.objects.filter(rtsp_url='RFJrWk9OVVJPUVRnM1IxaFNXazFFUXpFeE1VRT1U').values('uid')
+                if has_rtsp_url.exists():
+                    send_flag = self.runSendStop(has_rtsp_url[0]['uid'], has_rtsp_url[0]['password'], push_path)
+                    if send_flag:
+                        success += 1
+            return JsonResponse({'successStopNum': success})
 
     #把格式化时间转换成时间戳
     def str_to_timestamp(self, str_time=None, format='%Y-%m-%d %H:%M:%S'):
@@ -340,7 +350,7 @@ class deviceStatus(TemplateView):
         # print('command=>{command}'.format(command=command))
         command_url = "http://47.115.134.251/index.php?command={command}".format(command=command)
         try:
-            exec_res = requests.get(url=command_url, timeout=2)
+            exec_res = requests.get(url=command_url, timeout=5)
             res = exec_res.json()
             if res['code'] == 200:
                 return True

+ 2 - 1
controller/index.py

@@ -279,6 +279,7 @@ class oa2RtspStartView(TemplateView):
             # if send_flag:
             #     return JsonResponse({'msg': 'stop yes', 'code': 0})
 
+            # 此处后续应该用异步去发送指令
             if int(st) == 1:
                 send_flag = self.runSendStop(UID, PWD, MSG)
                 logger.info('----------send_flag---st=1-----------------')
@@ -306,7 +307,7 @@ class oa2RtspStartView(TemplateView):
             # stream_name = threading.Thread(target=self.runSendStop,args=(UID, PWD, MSG))
             # stream_name.start()
             #----------/新增关闭流的线程
-            stop_time = int(time.time()) + 2*60 + 8*3600
+            stop_time = int(time.time()) + 2*60
             expirationTime = time.strftime('%Y-%m-%dT%H:%MZ',time.localtime(stop_time))
             res_json = {
                 'endpointId': id,