修复 蓝鲸字库回调流程异常问题

This commit is contained in:
小肥羊 2025-07-15 14:44:55 +08:00
parent 13080a8f63
commit c88001c40c
2 changed files with 12 additions and 7 deletions

View File

@ -27,6 +27,7 @@ namespace Learn.VideoAnalysis.API.Expand
provider.ApplicationServices.UseScheduler(scheduler =>
{
//文件包分析
//scheduler.Schedule<NodePackageJob>().EveryMinute(); //每分钟执行一次
scheduler.Schedule<NodePackageJob>().EveryThirtyMinutes(); //每30分钟执行一次
});
}

View File

@ -35,11 +35,12 @@ namespace VideoAnalysisCore.Job
private readonly Repository<VideoTask> videoTaskDB;
private readonly IHttpClientFactory _clientFactory;
public NodePackageJob(Repository<Attachments> videoTaskDB,
Repository<NodePackageInfo> nodePackageInfoDB, Repository<VideoTask> videotaskDB)
Repository<NodePackageInfo> nodePackageInfoDB, Repository<VideoTask> videotaskDB, IHttpClientFactory clientFactory)
{
this.attachmentsDB = videoTaskDB;
this.nodePackageInfoDB = nodePackageInfoDB;
this.videoTaskDB = videotaskDB;
_clientFactory = clientFactory;
}
public async Task Invoke()
{
@ -84,9 +85,9 @@ namespace VideoAnalysisCore.Job
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 任务回调 数量{postData.Count} ...");
if (postData.Count() == 0)
return;
foreach (var item in taskArr)
foreach (var item in postData)
{
HttpResponseMessage responseMessage = null;
HttpResponseMessage? responseMessage = null;
try
{
var postUrl = !string.IsNullOrWhiteSpace(item.CallBackUrl)
@ -97,7 +98,7 @@ namespace VideoAnalysisCore.Job
var request = new HttpRequestMessage(HttpMethod.Post, postUrl);
request.Headers.Add("Area", item.Area); // 直接添加到本次请求头
request.Headers.Add("HostIP", item.HostIP); // 直接添加到本次请求头
request.Content = new StringContent(postData.ToJson(), Encoding.UTF8, "application/json");
request.Content = new StringContent(new object[] { item }.ToJson(), Encoding.UTF8, "application/json");
responseMessage = await apiClent.SendAsync(request);
if (responseMessage.IsSuccessStatusCode)
@ -105,7 +106,7 @@ namespace VideoAnalysisCore.Job
var res = await responseMessage.Content.ReadAsStringAsync();
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调结果 {res}");
await nodePackageInfoDB.AsUpdateable(postData)
await nodePackageInfoDB.AsUpdateable(item)
.UpdateColumns(it => new { it.SuccessTime })
.ExecuteCommandAsync();
}
@ -117,8 +118,11 @@ namespace VideoAnalysisCore.Job
}
catch (Exception ex)
{
var res = await responseMessage?.Content?.ReadAsStringAsync()??string.Empty;
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage.StatusCode} {res}");
if (responseMessage != null)
{
var res = (await responseMessage?.Content?.ReadAsStringAsync()) ?? string.Empty;
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage?.StatusCode} {res}");
}
Console.WriteLine(ex);
}
await Task.Delay(1000);