|
@@ -60,6 +60,8 @@ class CronDelDataView(View):
|
|
|
return self.UpdateConfiguration(response)
|
|
|
elif operation == 'cloud-log':
|
|
|
return self.uid_cloud_storage_upload_count(response)
|
|
|
+ elif operation == 'delDeviceLog': # 定时删除设备日志
|
|
|
+ return self.del_device_log(response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -286,6 +288,25 @@ class CronDelDataView(View):
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def del_device_log(response):
|
|
|
+ """
|
|
|
+ 定时删除设备日志
|
|
|
+ @param response: 响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ nowTime = int(time.time())
|
|
|
+ try:
|
|
|
+ cursor = connection.cursor()
|
|
|
+ month_ago_time = nowTime - 30 * 24 * 60 * 60 # 保留近30天的数据
|
|
|
+
|
|
|
+ sql = 'DELETE FROM `device_log` WHERE unix_timestamp(add_time)<{}'.format(month_ago_time)
|
|
|
+ cursor.execute(sql)
|
|
|
+ cursor.close()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
|
|
|
class CronUpdateDataView(View):
|
|
|
def get(self, request, *args, **kwargs):
|