S8FlowHandlerFailureNotifier.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Admin.NET.Plugin.ApprovalFlow.Service;
  2. using Microsoft.Extensions.Logging;
  3. namespace Admin.NET.Plugin.AiDOP.Service.S8;
  4. /// <summary>
  5. /// N-1:当 ApprovalFlow 引擎调用 S8 BizHandler(EXCEPTION_ESCALATION / EXCEPTION_CLOSURE)失败时,
  6. /// 写入 ado_s8_notification_log(channel = s8-invoke-handler-failed),让"不可见失败"变可见。
  7. /// 不做反查、不做去重、不做补偿;上抛仍由 ApprovalFlow 引擎完成。
  8. /// </summary>
  9. public class S8FlowHandlerFailureNotifier : IFlowHandlerFailureNotifier, ITransient
  10. {
  11. public const string AlertChannel = "s8-invoke-handler-failed";
  12. private static readonly HashSet<string> S8BizTypes = new(StringComparer.Ordinal)
  13. {
  14. "EXCEPTION_ESCALATION",
  15. "EXCEPTION_CLOSURE",
  16. };
  17. private readonly S8NotificationService _notificationService;
  18. private readonly ILogger<S8FlowHandlerFailureNotifier> _logger;
  19. public S8FlowHandlerFailureNotifier(
  20. S8NotificationService notificationService,
  21. ILogger<S8FlowHandlerFailureNotifier> logger)
  22. {
  23. _notificationService = notificationService;
  24. _logger = logger;
  25. }
  26. public async Task NotifyAsync(string bizType, long instanceId, Exception exception, CancellationToken cancellationToken = default)
  27. {
  28. if (!S8BizTypes.Contains(bizType))
  29. return;
  30. var payload = new
  31. {
  32. type = "FLOW_HANDLER_FAILED",
  33. message = "S8 审批流回调 Handler 抛异常,已被引擎上抛;请人工核对业务单与审批实例状态",
  34. bizType,
  35. instanceId,
  36. errorType = exception.GetType().FullName,
  37. errorMessage = exception.Message,
  38. detectedAt = DateTime.Now
  39. };
  40. await _notificationService.SendAsync(0, 0, null, AlertChannel, payload);
  41. _logger.LogWarning(
  42. "S8 FlowHandler 失败已落告警: BizType={BizType}, InstanceId={InstanceId}, ErrorType={ErrorType}, ErrorMessage={ErrorMessage}",
  43. bizType, instanceId, exception.GetType().FullName, exception.Message);
  44. }
  45. }