(action: str, func)
| 33 | |
| 34 | |
| 35 | def _invoke(action: str, func): |
| 36 | # NOTE: 编排层统一记录入口与结果,便于区分 UI 事件日志与服务层执行日志 |
| 37 | start = time.perf_counter() |
| 38 | log_event(logging.INFO, "core_action_started", f"核心调用开始: {action}", action=action, status="started") |
| 39 | try: |
| 40 | result = func() |
| 41 | duration_ms = int((time.perf_counter() - start) * 1000) |
| 42 | if getattr(result, "ok", False): |
| 43 | log_event(logging.INFO, "core_action_finished", f"核心调用成功: {action}", action=action, status="ok", duration_ms=duration_ms) |
| 44 | else: |
| 45 | err_msg = (getattr(result, "error", None) or {}).get("message", "核心调用失败") |
| 46 | log_event( |
| 47 | logging.ERROR, |
| 48 | "core_action_finished", |
| 49 | f"核心调用失败: {action}", |
| 50 | action=action, |
| 51 | status="failed", |
| 52 | duration_ms=duration_ms, |
| 53 | error_type=(getattr(result, "error", None) or {}).get("code", "CORE_ACTION_FAILED"), |
| 54 | error_message=err_msg, |
| 55 | ) |
| 56 | return result |
| 57 | except Exception as e: |
| 58 | duration_ms = int((time.perf_counter() - start) * 1000) |
| 59 | log_event( |
| 60 | logging.ERROR, |
| 61 | "core_action_exception", |
| 62 | f"核心调用异常: {action} - {e}", |
| 63 | action=action, |
| 64 | status="failed", |
| 65 | duration_ms=duration_ms, |
| 66 | error_type=type(e).__name__, |
| 67 | error_message=str(e), |
| 68 | traceback=traceback.format_exc(), |
| 69 | exc_info=True, |
| 70 | ) |
| 71 | raise |
| 72 | |
| 73 | |
| 74 | def pause_updates(max_days: int = 18300): |
no test coverage detected