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
SystemLog.log( if has_app_context():
level=status, try:
message=full_message, SystemLog.log(
module='daemon', level=status,
extra_data=extra_info message=full_message,
) module='daemon',
extra_data=extra_info
# Also log to application logger )
except Exception as db_error:
logger.error(f"Failed to log daemon event to database: {str(db_error)}")
# 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':
......
...@@ -24,4 +24,5 @@ psutil==6.1.0 ...@@ -24,4 +24,5 @@ psutil==6.1.0
watchdog==6.0.0 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
\ No newline at end of file redis==5.2.0
\ No newline at end of file
...@@ -19,4 +19,5 @@ psutil==6.1.0 ...@@ -19,4 +19,5 @@ psutil==6.1.0
watchdog==6.0.0 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
\ No newline at end of file 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