Fix runtime issues: add Redis dependency and Flask context handling

- Add redis==5.2.0 to requirements.txt and requirements-build.txt
- Fix Flask application context issue in log_daemon_event function
- Add has_app_context() check before database logging operations
- Ensure daemon logging works both inside and outside Flask context
parent 82995299
Pipeline #173 failed with stages
import logging import logging
import json import json
from datetime import datetime from datetime import datetime
from flask import request, current_app from flask import request, current_app, has_app_context
from app import db from app import db
from app.models import SystemLog from app.models import SystemLog
...@@ -261,15 +261,19 @@ def log_daemon_event(event_type, message, status='INFO', error_message=None, ext ...@@ -261,15 +261,19 @@ def log_daemon_event(event_type, message, status='INFO', error_message=None, ext
if extra_data: if extra_data:
extra_info.update(extra_data) extra_info.update(extra_data)
# Log to database # Only log to database if we have an application context
if has_app_context():
try:
SystemLog.log( SystemLog.log(
level=status, level=status,
message=full_message, message=full_message,
module='daemon', module='daemon',
extra_data=extra_info extra_data=extra_info
) )
except Exception as db_error:
logger.error(f"Failed to log daemon event to database: {str(db_error)}")
# Also log to application logger # Always log to application logger
if status == 'INFO': if status == 'INFO':
logger.info(full_message) logger.info(full_message)
elif status == 'WARNING': elif status == 'WARNING':
......
...@@ -25,3 +25,4 @@ watchdog==6.0.0 ...@@ -25,3 +25,4 @@ watchdog==6.0.0
click==8.1.7 click==8.1.7
colorlog==6.8.2 colorlog==6.8.2
marshmallow==3.23.1 marshmallow==3.23.1
redis==5.2.0
\ No newline at end of file
...@@ -20,3 +20,4 @@ watchdog==6.0.0 ...@@ -20,3 +20,4 @@ watchdog==6.0.0
click==8.1.7 click==8.1.7
colorlog==6.8.2 colorlog==6.8.2
marshmallow==3.23.1 marshmallow==3.23.1
redis==5.2.0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment