fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -456,13 +456,13 @@ class OpsManager:
|
||||
self._evaluator_thread = None
|
||||
self._register_default_evaluators()
|
||||
|
||||
def _get_db(self):
|
||||
def _get_db(self) -> None:
|
||||
"""获取数据库连接"""
|
||||
conn = sqlite3.connect(self.db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
def _register_default_evaluators(self):
|
||||
def _register_default_evaluators(self) -> None:
|
||||
"""注册默认的告警评估器"""
|
||||
self._alert_evaluators[AlertRuleType.THRESHOLD.value] = self._evaluate_threshold_rule
|
||||
self._alert_evaluators[AlertRuleType.ANOMALY.value] = self._evaluate_anomaly_rule
|
||||
@@ -1249,7 +1249,7 @@ class OpsManager:
|
||||
|
||||
return self.get_alert(alert_id)
|
||||
|
||||
def _increment_suppression_count(self, alert_id: str):
|
||||
def _increment_suppression_count(self, alert_id: str) -> None:
|
||||
"""增加告警抑制计数"""
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
@@ -1262,7 +1262,7 @@ class OpsManager:
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
def _update_alert_notification_status(self, alert_id: str, channel_id: str, success: bool):
|
||||
def _update_alert_notification_status(self, alert_id: str, channel_id: str, success: bool) -> None:
|
||||
"""更新告警通知状态"""
|
||||
with self._get_db() as conn:
|
||||
row = conn.execute("SELECT notification_sent FROM alerts WHERE id = ?", (alert_id,)).fetchone()
|
||||
@@ -1276,7 +1276,7 @@ class OpsManager:
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
def _update_channel_stats(self, channel_id: str, success: bool):
|
||||
def _update_channel_stats(self, channel_id: str, success: bool) -> None:
|
||||
"""更新渠道统计"""
|
||||
now = datetime.now().isoformat()
|
||||
|
||||
@@ -1769,9 +1769,7 @@ class OpsManager:
|
||||
return self._row_to_scaling_event(row)
|
||||
return None
|
||||
|
||||
def update_scaling_event_status(
|
||||
self, event_id: str, status: str, error_message: str = None
|
||||
) -> ScalingEvent | None:
|
||||
def update_scaling_event_status(self, event_id: str, status: str, error_message: str = None) -> ScalingEvent | None:
|
||||
"""更新扩缩容事件状态"""
|
||||
now = datetime.now().isoformat()
|
||||
|
||||
@@ -2339,7 +2337,7 @@ class OpsManager:
|
||||
|
||||
return record
|
||||
|
||||
def _complete_backup(self, record_id: str, size_bytes: int, checksum: str = None):
|
||||
def _complete_backup(self, record_id: str, size_bytes: int, checksum: str = None) -> None:
|
||||
"""完成备份"""
|
||||
now = datetime.now().isoformat()
|
||||
checksum = checksum or hashlib.sha256(str(time.time()).encode()).hexdigest()[:16]
|
||||
|
||||
Reference in New Issue
Block a user