updated card and board
This commit is contained in:
@@ -2,6 +2,7 @@ from flask import Flask, request, jsonify, render_template, redirect, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import threading
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///logs.db'
|
||||
@@ -48,7 +49,7 @@ def get_logs():
|
||||
|
||||
@app.route('/cleanup', methods=['DELETE'])
|
||||
def cleanup_logs():
|
||||
cutoff_date = datetime.utcnow() - timedelta(days=10)
|
||||
cutoff_date = datetime.utcnow() - timedelta(hours=24)
|
||||
Log.query.filter(Log.timestamp < cutoff_date).delete()
|
||||
db.session.commit()
|
||||
return jsonify({'status': 'success', 'message': 'Old logs deleted'})
|
||||
@@ -108,5 +109,13 @@ def get_board_logs(hostname):
|
||||
logs = Log.query.filter_by(hostname=hostname).order_by(Log.timestamp.desc()).all()
|
||||
return jsonify({'logs': [{'timestamp': log.timestamp, 'message': log.message} for log in logs]})
|
||||
|
||||
def schedule_cleanup():
|
||||
with app.app_context():
|
||||
cutoff_date = datetime.utcnow() - timedelta(hours=24)
|
||||
Log.query.filter(Log.timestamp < cutoff_date).delete()
|
||||
db.session.commit()
|
||||
threading.Timer(3600, schedule_cleanup).start()
|
||||
|
||||
if __name__ == '__main__':
|
||||
schedule_cleanup() # Start the cleanup scheduler
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
Reference in New Issue
Block a user