diff --git a/Healthbeat.py b/Healthbeat.py index 8deee36..7f9bb7a 100644 --- a/Healthbeat.py +++ b/Healthbeat.py @@ -27,13 +27,13 @@ class Camera: else: logging.warning("摄像头ID: %s, 状态: 离线" % (self.id)) - if (status == 1 and self.status == 2) or (status == 2 and self.status == 1): - conn = get_connection() + #if (status == 1 and self.status == 2) or (status == 2 and self.status == 1): + conn = get_connection() - with conn: - with conn.cursor() as cursor: - cursor.execute("update devices set state = %s, updated_at = %s where id = %s", (status, datetime.datetime.now(), self.id)) - conn.commit() + with conn: + with conn.cursor() as cursor: + cursor.execute("update devices set state = %s, updated_at = %s where id = %s", (status, datetime.datetime.now(), self.id)) + conn.commit() 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')