Update
parent
76b0f2ae21
commit
175ff36bce
|
|
@ -13,6 +13,7 @@ class Camera:
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
def healthbeat(self):
|
def healthbeat(self):
|
||||||
|
try:
|
||||||
cap = cv2.VideoCapture(self.rtsp)
|
cap = cv2.VideoCapture(self.rtsp)
|
||||||
ret, _ = cap.read()
|
ret, _ = cap.read()
|
||||||
cap.release()
|
cap.release()
|
||||||
|
|
@ -30,9 +31,11 @@ class Camera:
|
||||||
|
|
||||||
with conn:
|
with conn:
|
||||||
with conn.cursor() as cursor:
|
with conn.cursor() as cursor:
|
||||||
cursor.execute("update devices set status = %s where id = %s", (status, self.id))
|
cursor.execute("update devices set status = %s, updated_at = %s where id = %s", (status, self.id, datetime.datetime.now()))
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"摄像头ID: {self.id}, 检测状态时发生错误: {str(e)}")
|
||||||
|
|
||||||
def init_logger():
|
def init_logger():
|
||||||
logging.basicConfig(filename='healthbeat.log', level=logging.INFO, format='[%(asctime)s] %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
logging.basicConfig(filename='healthbeat.log', level=logging.INFO, format='[%(asctime)s] %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
|
|
@ -60,10 +63,15 @@ if __name__ == '__main__':
|
||||||
cursor.execute("SELECT id, status, extends FROM devices WHERE type = 1 AND status in (1, 2) AND supplier_key not in ('device-supplier-biang', 'device-supplier-yunfei') ORDER BY id ASC")
|
cursor.execute("SELECT id, status, extends FROM devices WHERE type = 1 AND status in (1, 2) AND supplier_key not in ('device-supplier-biang', 'device-supplier-yunfei') ORDER BY id ASC")
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
threads = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
c = Camera(row[0], row[2]["rtsp_url"], row[1])
|
c = Camera(row[0], row[2]["rtsp_url"], row[1])
|
||||||
t = threading.Thread(target=c.healthbeat)
|
t = threading.Thread(target=c.healthbeat)
|
||||||
|
threads.append(t)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
for t in threads:
|
||||||
|
t.join()
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
Loading…
Reference in New Issue