IMdpTargetPushExecutor.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
  2. namespace Admin.NET.Plugin.AiDOP.DataPlatform.Executors;
  3. /// <summary>出站执行器:按 mdp_source.source_type 推送单条 Outbox。</summary>
  4. public interface IMdpTargetPushExecutor
  5. {
  6. /// <summary>API / DB</summary>
  7. string SupportedType { get; }
  8. Task<MdpPushResult> PushAsync(MdpSource source, MdpOutbox item, CancellationToken ct = default);
  9. }
  10. public sealed class MdpPushResult
  11. {
  12. public bool Success { get; set; }
  13. public int AffectedRows { get; set; }
  14. public string? ResponseJson { get; set; }
  15. public string? ErrorMessage { get; set; }
  16. /// <summary>true 表示识别为「已处理过」,幂等跳过,应记为成功。</summary>
  17. public bool IdempotentSkip { get; set; }
  18. /// <summary>true 表示总开关关闭,调用方不得改 outbox 状态、不得递增 retry_count。</summary>
  19. public bool Held { get; set; }
  20. public static MdpPushResult Ok(int affected = 1, string? response = null) =>
  21. new() { Success = true, AffectedRows = affected, ResponseJson = response };
  22. public static MdpPushResult Skip(string? response = null) =>
  23. new() { Success = true, IdempotentSkip = true, AffectedRows = 0, ResponseJson = response };
  24. public static MdpPushResult Fail(string error, string? response = null) =>
  25. new() { Success = false, ErrorMessage = error, ResponseJson = response };
  26. public static MdpPushResult Hold(string reason) =>
  27. new() { Success = false, Held = true, ErrorMessage = reason };
  28. }