优化 任务异常后重试机制
This commit is contained in:
parent
935c6a9eb1
commit
90cf56efec
|
|
@ -157,6 +157,8 @@ namespace Learn.VideoAnalysis.Controllers
|
|||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
if(await videoTaskDB.IsAnyAsync(s=>s.TagId == req.TagId) )
|
||||
return BadRequest("重复添加");
|
||||
// 自动映射属性到哈希
|
||||
var task = new VideoTask()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -183,15 +183,15 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
|
|||
|
||||
private async Task<HttpResponseMessage> PostJsonStreamAsync(string path, string json)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiKey);
|
||||
var request = ToHttpRequest(path);
|
||||
var maxRestart = 4;
|
||||
var errorMSG = new Exception[maxRestart];
|
||||
for (int i = 0; i < maxRestart; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiKey);
|
||||
var request = ToHttpRequest(path);
|
||||
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,6 +283,7 @@ namespace VideoAnalysisCore.Common
|
|||
var tID = long.Parse(taskId);
|
||||
if (action is not null)
|
||||
{
|
||||
var errArr = new Exception[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 开始执行 " + key + " " + taskId);
|
||||
|
|
@ -299,11 +300,16 @@ namespace VideoAnalysisCore.Common
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errArr[i] = ex;
|
||||
Console.WriteLine("====================[出现异常]====================");
|
||||
Console.WriteLine(ex.Message);
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
Console.WriteLine("==============================================");
|
||||
Thread.Sleep(1000);
|
||||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId );
|
||||
await SetTaskErrorMessage(tID, ex);
|
||||
}
|
||||
}
|
||||
await SetTaskErrorMessage(tID, errArr.First());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue