fix: auto-fix code issues (cron)
- 修复隐式 Optional 类型注解 (RUF013) - 修复不必要的赋值后返回 (RET504) - 优化列表推导式 (PERF401) - 修复未使用的参数 (ARG002) - 清理重复导入 - 优化异常处理
This commit is contained in:
@@ -264,7 +264,9 @@ class WebhookNotifier:
|
||||
secret_enc = config.secret.encode("utf-8")
|
||||
string_to_sign = f"{timestamp}\n{config.secret}"
|
||||
hmac_code = hmac.new(
|
||||
secret_enc, string_to_sign.encode("utf-8"), digestmod=hashlib.sha256,
|
||||
secret_enc,
|
||||
string_to_sign.encode("utf-8"),
|
||||
digestmod=hashlib.sha256,
|
||||
).digest()
|
||||
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
|
||||
url = f"{config.url}×tamp = {timestamp}&sign = {sign}"
|
||||
@@ -497,7 +499,10 @@ class WorkflowManager:
|
||||
conn.close()
|
||||
|
||||
def list_workflows(
|
||||
self, project_id: str = None, status: str = None, workflow_type: str = None,
|
||||
self,
|
||||
project_id: str | None = None,
|
||||
status: str = None,
|
||||
workflow_type: str = None,
|
||||
) -> list[Workflow]:
|
||||
"""列出工作流"""
|
||||
conn = self.db.get_conn()
|
||||
@@ -518,7 +523,8 @@ class WorkflowManager:
|
||||
where_clause = " AND ".join(conditions) if conditions else "1 = 1"
|
||||
|
||||
rows = conn.execute(
|
||||
f"SELECT * FROM workflows WHERE {where_clause} ORDER BY created_at DESC", params,
|
||||
f"SELECT * FROM workflows WHERE {where_clause} ORDER BY created_at DESC",
|
||||
params,
|
||||
).fetchall()
|
||||
|
||||
return [self._row_to_workflow(row) for row in rows]
|
||||
@@ -780,7 +786,8 @@ class WorkflowManager:
|
||||
conn = self.db.get_conn()
|
||||
try:
|
||||
row = conn.execute(
|
||||
"SELECT * FROM webhook_configs WHERE id = ?", (webhook_id,),
|
||||
"SELECT * FROM webhook_configs WHERE id = ?",
|
||||
(webhook_id,),
|
||||
).fetchone()
|
||||
|
||||
if not row:
|
||||
@@ -962,9 +969,9 @@ class WorkflowManager:
|
||||
|
||||
def list_logs(
|
||||
self,
|
||||
workflow_id: str = None,
|
||||
task_id: str = None,
|
||||
status: str = None,
|
||||
workflow_id: str | None = None,
|
||||
task_id: str | None = None,
|
||||
status: str | None = None,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
) -> list[WorkflowLog]:
|
||||
@@ -1074,7 +1081,7 @@ class WorkflowManager:
|
||||
|
||||
# ==================== Workflow Execution ====================
|
||||
|
||||
async def execute_workflow(self, workflow_id: str, input_data: dict = None) -> dict:
|
||||
async def execute_workflow(self, workflow_id: str, input_data: dict | None = None) -> dict:
|
||||
"""执行工作流"""
|
||||
workflow = self.get_workflow(workflow_id)
|
||||
if not workflow:
|
||||
@@ -1159,7 +1166,10 @@ class WorkflowManager:
|
||||
raise
|
||||
|
||||
async def _execute_tasks_with_deps(
|
||||
self, tasks: list[WorkflowTask], input_data: dict, log_id: str,
|
||||
self,
|
||||
tasks: list[WorkflowTask],
|
||||
input_data: dict,
|
||||
log_id: str,
|
||||
) -> dict:
|
||||
"""按依赖顺序执行任务"""
|
||||
results = {}
|
||||
@@ -1413,7 +1423,10 @@ class WorkflowManager:
|
||||
# ==================== Notification ====================
|
||||
|
||||
async def _send_workflow_notification(
|
||||
self, workflow: Workflow, results: dict, success: bool = True,
|
||||
self,
|
||||
workflow: Workflow,
|
||||
results: dict,
|
||||
success: bool = True,
|
||||
) -> None:
|
||||
"""发送工作流执行通知"""
|
||||
if not workflow.webhook_ids:
|
||||
|
||||
Reference in New Issue
Block a user