Skip to content

Commit

Permalink
feat: 调整错误通知样式
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Feb 27, 2024
1 parent aedb2cc commit f85f508
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions utils/config_generators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import partial
from typing import Any, Dict, Union

from prefect.client.schemas.schedules import CronSchedule
Expand All @@ -18,8 +19,8 @@ def generate_flow_config(
"retries": retries,
"retry_delay_seconds": retry_delay_seconds,
"timeout_seconds": timeout,
"on_failure": [on_failure_or_crashed],
"on_crashed": [on_failure_or_crashed],
"on_failure": [partial(on_failure_or_crashed, status="Failed")],
"on_crashed": [partial(on_failure_or_crashed, status="Crashed")],
}


Expand Down
17 changes: 13 additions & 4 deletions utils/event_handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

from httpx import AsyncClient
from prefect.client.schemas.objects import Flow, FlowRun, State

Expand All @@ -6,7 +8,9 @@
CLIENT = AsyncClient(http2=True)


async def on_failure_or_crashed(flow: Flow, flow_run: FlowRun, state: State) -> None:
async def on_failure_or_crashed(
status: Literal["Failed", "Crashed"], flow: Flow, flow_run: FlowRun, state: State
) -> None:
if not CONFIG.feishu_notification.enabled:
return

Expand All @@ -19,14 +23,19 @@ async def on_failure_or_crashed(flow: Flow, flow_run: FlowRun, state: State) ->
"data": {
"template_id": CONFIG.feishu_notification.failure_card_id,
"template_variable": {
"status": flow_run.state_name,
"status": status,
"flow_name": flow.name,
"run_name": flow_run.name,
"deployment_name": "[To-Do]",
"parameters": str(flow_run.parameters),
"start_time": flow_run.start_time.strftime(r"%Y-%m-%d %H:%M:%S")
if flow_run.start_time
else "[未知]",
"error_message": state.message,
"retries": flow_run.empirical_policy.retries,
"error_message": state.message.replace(
"Flow run encountered an exception. ", ""
)
if state.message
else "[未知]",
"details_url": f"http://prod-server:4200/flow-runs/flow-run/{flow_run.id}",
},
},
Expand Down

0 comments on commit f85f508

Please sign in to comment.