fix(api): resolve 時 DB 記錄不存在視為成功
根因: Incident 可能因 DB 寫入失敗只存在於 Redis 修復: 只要 Redis 更新成功就算成功 (API 只讀 Redis) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -569,7 +569,7 @@ class ProposalService:
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
# 2. 更新 DB
|
||||
# 2. 更新 DB (如果存在)
|
||||
try:
|
||||
async with get_db_context() as db:
|
||||
stmt = select(IncidentRecord).where(
|
||||
@@ -586,6 +586,15 @@ class ProposalService:
|
||||
"resolve_incident_db_updated",
|
||||
incident_id=incident_id,
|
||||
)
|
||||
else:
|
||||
# DB 沒有記錄但 Redis 有 - 這是可接受的狀態
|
||||
# (Incident 可能因 DB 寫入失敗只存在 Redis)
|
||||
db_ok = True # 視為成功,因為沒有需要更新的記錄
|
||||
logger.warning(
|
||||
"resolve_incident_db_not_found",
|
||||
incident_id=incident_id,
|
||||
note="Incident exists in Redis but not in DB, this is acceptable",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
"resolve_incident_db_error",
|
||||
@@ -593,7 +602,8 @@ class ProposalService:
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
success = redis_ok and db_ok
|
||||
# 只要 Redis 更新成功就算成功(API 只讀 Redis)
|
||||
success = redis_ok
|
||||
logger.info(
|
||||
"resolve_incident_completed",
|
||||
incident_id=incident_id,
|
||||
|
||||
Reference in New Issue
Block a user