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 json
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.models import SystemLog
......@@ -261,15 +261,19 @@ def log_daemon_event(event_type, message, status='INFO', error_message=None, ext
if extra_data:
extra_info.update(extra_data)
# Log to database
SystemLog.log(
level=status,
message=full_message,
module='daemon',
extra_data=extra_info
)
# Also log to application logger
# Only log to database if we have an application context
if has_app_context():
try:
SystemLog.log(
level=status,
message=full_message,
module='daemon',
extra_data=extra_info
)
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':
logger.info(full_message)
elif status == 'WARNING':
......
......@@ -24,4 +24,5 @@ psutil==6.1.0
watchdog==6.0.0
click==8.1.7
colorlog==6.8.2
marshmallow==3.23.1
\ No newline at end of file
marshmallow==3.23.1
redis==5.2.0
\ No newline at end of file
......@@ -19,4 +19,5 @@ psutil==6.1.0
watchdog==6.0.0
click==8.1.7
colorlog==6.8.2
marshmallow==3.23.1
\ No newline at end of file
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