fix: 增强SKU异步任务失败错误明细
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 51s
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 51s
This commit is contained in:
@@ -396,7 +396,7 @@ public sealed class ProductController(
|
|||||||
{
|
{
|
||||||
entity.Status = ProductSkuSaveJobStatus.Failed;
|
entity.Status = ProductSkuSaveJobStatus.Failed;
|
||||||
entity.FailedCount = entity.ProgressTotal;
|
entity.FailedCount = entity.ProgressTotal;
|
||||||
entity.ErrorMessage = Truncate(ex.Message, 2000);
|
entity.ErrorMessage = Truncate(BuildDetailedErrorMessage(ex), 2000);
|
||||||
entity.FinishedAt = DateTime.UtcNow;
|
entity.FinishedAt = DateTime.UtcNow;
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
return ApiResponse<ProductSkuSaveJobResponse>.Error(ErrorCodes.InternalServerError, "SKU 保存任务创建失败");
|
return ApiResponse<ProductSkuSaveJobResponse>.Error(ErrorCodes.InternalServerError, "SKU 保存任务创建失败");
|
||||||
@@ -1370,6 +1370,32 @@ public sealed class ProductController(
|
|||||||
return value.Length <= maxLength ? value : value[..maxLength];
|
return value.Length <= maxLength ? value : value[..maxLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string BuildDetailedErrorMessage(Exception ex)
|
||||||
|
{
|
||||||
|
var lines = new List<string>();
|
||||||
|
var current = ex;
|
||||||
|
var depth = 0;
|
||||||
|
const int maxDepth = 8;
|
||||||
|
|
||||||
|
while (current is not null && depth < maxDepth)
|
||||||
|
{
|
||||||
|
var prefix = depth == 0 ? "Exception" : $"Inner[{depth}]";
|
||||||
|
var message = string.IsNullOrWhiteSpace(current.Message)
|
||||||
|
? "(no message)"
|
||||||
|
: current.Message.Trim();
|
||||||
|
lines.Add($"{prefix} {current.GetType().Name}: {message}");
|
||||||
|
current = current.InnerException;
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current is not null)
|
||||||
|
{
|
||||||
|
lines.Add($"Inner[{depth}] ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(Environment.NewLine, lines);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<ProductRelationState> LoadProductRelationStateAsync(
|
private async Task<ProductRelationState> LoadProductRelationStateAsync(
|
||||||
long productId,
|
long productId,
|
||||||
long storeId,
|
long storeId,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public sealed class ProductSkuSaveJobRunner(
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "SKU 异步保存任务执行失败,JobId={JobId}", jobId);
|
logger.LogError(ex, "SKU 异步保存任务执行失败,JobId={JobId}", jobId);
|
||||||
await MarkFailedAsync(jobMeta.Id, ex.Message);
|
await MarkFailedAsync(jobMeta.Id, BuildDetailedErrorMessage(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,5 +159,31 @@ public sealed class ProductSkuSaveJobRunner(
|
|||||||
return value.Length <= maxLength ? value : value[..maxLength];
|
return value.Length <= maxLength ? value : value[..maxLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string BuildDetailedErrorMessage(Exception ex)
|
||||||
|
{
|
||||||
|
var lines = new List<string>();
|
||||||
|
var current = ex;
|
||||||
|
var depth = 0;
|
||||||
|
const int maxDepth = 8;
|
||||||
|
|
||||||
|
while (current is not null && depth < maxDepth)
|
||||||
|
{
|
||||||
|
var prefix = depth == 0 ? "Exception" : $"Inner[{depth}]";
|
||||||
|
var message = string.IsNullOrWhiteSpace(current.Message)
|
||||||
|
? "(no message)"
|
||||||
|
: current.Message.Trim();
|
||||||
|
lines.Add($"{prefix} {current.GetType().Name}: {message}");
|
||||||
|
current = current.InnerException;
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current is not null)
|
||||||
|
{
|
||||||
|
lines.Add($"Inner[{depth}] ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(Environment.NewLine, lines);
|
||||||
|
}
|
||||||
|
|
||||||
private sealed record JobMeta(long Id, long TenantId);
|
private sealed record JobMeta(long Id, long TenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user