修复 尝试解决多线程sql异常问题
This commit is contained in:
parent
1cb53fe405
commit
1151068185
|
|
@ -39,7 +39,7 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
bool tableLoading = false;
|
bool tableLoading = false;
|
||||||
private VideoTaskDto selectData;
|
private VideoTaskDto selectData;
|
||||||
private bool rowRestartLoading = false;
|
private bool rowRestartLoading = false;
|
||||||
private VideoTaskDto reStartTask ;
|
private VideoTaskDto reStartTask;
|
||||||
|
|
||||||
static TextValue[] SelectDataSource =
|
static TextValue[] SelectDataSource =
|
||||||
Enum.GetValues(typeof(RedisChannelEnum))
|
Enum.GetValues(typeof(RedisChannelEnum))
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
.Select(s => new TextValue(s.ToString(), (int)s))
|
.Select(s => new TextValue(s.ToString(), (int)s))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
int selectEnum = 1;
|
int selectEnum = 1;
|
||||||
int selectDefaultValue =1;
|
int selectDefaultValue = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 点击重试
|
/// 点击重试
|
||||||
|
|
@ -63,17 +63,17 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
}
|
}
|
||||||
void PreviewTask(VideoTaskDto task)
|
void PreviewTask(VideoTaskDto task)
|
||||||
{
|
{
|
||||||
NavigationManager.NavigateTo("/VideoTaskShow/"+task.Id);
|
NavigationManager.NavigateTo("/VideoTaskShow/" + task.Id);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 重试
|
/// 重试
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query"></param>
|
/// <param name="query"></param>
|
||||||
async void ReStart()
|
async Task ReStart()
|
||||||
{
|
{
|
||||||
await redisManager.ClearTaskError(reStartTask.Id);
|
await redisManager.ClearTaskError(reStartTask.Id);
|
||||||
_=Task.Run(() =>
|
await Task.Run(async () =>
|
||||||
redisManager.InsertChannel((RedisChannelEnum)selectEnum, reStartTask.Id)
|
await redisManager.InsertChannel((RedisChannelEnum)selectEnum, reStartTask.Id)
|
||||||
);
|
);
|
||||||
modalShow = false;
|
modalShow = false;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
.Where(where)
|
.Where(where)
|
||||||
.Select<VideoTaskDto>()
|
.Select<VideoTaskDto>()
|
||||||
.OrderByDescending(s => s.Id)
|
.OrderByDescending(s => s.Id)
|
||||||
.ToPageListAsync(query.PageIndex , query.PageSize, _total);
|
.ToPageListAsync(query.PageIndex, query.PageSize, _total);
|
||||||
|
|
||||||
tableLoading = false;
|
tableLoading = false;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
|
|
@ -130,18 +130,18 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
var data = redisManager.Redis.HMGet<string>(RedisExpandKey.Task(item.Id),
|
var data = redisManager.Redis.HMGet<string>(RedisExpandKey.Task(item.Id),
|
||||||
"Progress", "LastEnum", "StartTime", "ErrorMessage");
|
"Progress", "LastEnum", "StartTime", "ErrorMessage");
|
||||||
item.Progress = data[0];
|
item.Progress = data[0];
|
||||||
item.LastEnum = data[1] == null ?default:data[1].ToEnum<RedisChannelEnum>() ?? default;
|
item.LastEnum = data[1] == null ? default : data[1].ToEnum<RedisChannelEnum>() ?? default;
|
||||||
item.StartTimeDic = data[2]==null?null: System.Text.Json.JsonSerializer.Deserialize<Dictionary<RedisChannelEnum, DateTime>>(data[2]) ?? null;
|
item.StartTimeDic = data[2] == null ? null : System.Text.Json.JsonSerializer.Deserialize<Dictionary<RedisChannelEnum, DateTime>>(data[2]) ?? null;
|
||||||
item.ErrorMessage = data[3];
|
item.ErrorMessage = data[3];
|
||||||
rowRestartLoading = false;
|
rowRestartLoading = false;
|
||||||
var statusStr = "wait";
|
var statusStr = "wait";
|
||||||
var dic = rowData.Data.StartTimeDic;
|
var dic = rowData.Data.StartTimeDic;
|
||||||
if (dic is null)
|
if (dic is null)
|
||||||
statusStr= "wait";
|
statusStr = "wait";
|
||||||
else if (!string.IsNullOrEmpty(rowData.Data.ErrorMessage))
|
else if (!string.IsNullOrEmpty(rowData.Data.ErrorMessage))
|
||||||
statusStr= "error";
|
statusStr = "error";
|
||||||
else if (dic.ContainsKey(RedisChannelEnum.结束任务))
|
else if (dic.ContainsKey(RedisChannelEnum.结束任务))
|
||||||
statusStr= "finish";
|
statusStr = "finish";
|
||||||
item.TaskStatus = statusStr;
|
item.TaskStatus = statusStr;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +158,7 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
}
|
}
|
||||||
private void OnExpand(RowData<VideoTaskDto> rowData)
|
private void OnExpand(RowData<VideoTaskDto> rowData)
|
||||||
{
|
{
|
||||||
if(rowData.Expanded)
|
if (rowData.Expanded)
|
||||||
RowRload(rowData);
|
RowRload(rowData);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,8 @@ namespace VideoAnalysisCore.Common.Expand
|
||||||
if (ex.Parametres == null) return;
|
if (ex.Parametres == null) return;
|
||||||
//var originColor = Console.ForegroundColor;
|
//var originColor = Console.ForegroundColor;
|
||||||
//Console.ForegroundColor = ConsoleColor.DarkRed;
|
//Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||||
Console.WriteLine($"【{DateTime.Now}——错误SQL - [{config.ConfigId}]】\r\n"+ ex.Message + "\r\n" + UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
|
Console.WriteLine($"【{DateTime.Now}——错误SQL - [{config.ConfigId}]】\r\n"+ ex.Message + "\r\n"
|
||||||
|
+ UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
//Console.ForegroundColor = originColor;
|
//Console.ForegroundColor = originColor;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ namespace VideoAnalysisCore.Common
|
||||||
public class RedisManager
|
public class RedisManager
|
||||||
{
|
{
|
||||||
public static bool StopTask { get; set; } = false;
|
public static bool StopTask { get; set; } = false;
|
||||||
public static Dictionary<RedisChannelEnum, Func<string,Task>> SubscribeList = new Dictionary<RedisChannelEnum, Func<string, Task>>();
|
public static Dictionary<RedisChannelEnum, Func<string, Task>> SubscribeList = new Dictionary<RedisChannelEnum, Func<string, Task>>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 队列池
|
/// 队列池
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -178,7 +178,7 @@ namespace VideoAnalysisCore.Common
|
||||||
/// 缓存GPT任务缓存
|
/// 缓存GPT任务缓存
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="taskId"></param>
|
/// <param name="taskId"></param>
|
||||||
public void SetTaskGPTCached(object taskId,string time, object? data)
|
public void SetTaskGPTCached(object taskId, string time, object? data)
|
||||||
{
|
{
|
||||||
Redis.Set(RedisExpandKey.TaskGPT(taskId) + ":" + time, data, 3600 * 24);
|
Redis.Set(RedisExpandKey.TaskGPT(taskId) + ":" + time, data, 3600 * 24);
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +264,7 @@ namespace VideoAnalysisCore.Common
|
||||||
//if (gptRes is null)
|
//if (gptRes is null)
|
||||||
// throw new Exception("未能读取到GPT处理结果");
|
// throw new Exception("未能读取到GPT处理结果");
|
||||||
//删除任务执行状态
|
//删除任务执行状态
|
||||||
await Redis.LRemAsync(RedisExpandKey.IDTask,1,task);
|
await Redis.LRemAsync(RedisExpandKey.IDTask, 1, task);
|
||||||
var taskData = await videoTaskDB
|
var taskData = await videoTaskDB
|
||||||
.GetFirstAsync(s => s.Id == tId);
|
.GetFirstAsync(s => s.Id == tId);
|
||||||
if (taskData.Captions == "[]")
|
if (taskData.Captions == "[]")
|
||||||
|
|
@ -275,7 +275,7 @@ namespace VideoAnalysisCore.Common
|
||||||
|
|
||||||
//未使用结果暂时屏蔽
|
//未使用结果暂时屏蔽
|
||||||
//taskData.ChatAnalysis = JsonSerializer.Serialize(gptRes);
|
//taskData.ChatAnalysis = JsonSerializer.Serialize(gptRes);
|
||||||
taskData.ChatAnalysisScore =0;
|
taskData.ChatAnalysisScore = 0;
|
||||||
taskData.ErrorMessage = string.Empty;
|
taskData.ErrorMessage = string.Empty;
|
||||||
taskData.LastEnum = RedisChannelEnum.结束任务;
|
taskData.LastEnum = RedisChannelEnum.结束任务;
|
||||||
taskData.EndTime = DateTime.Now;
|
taskData.EndTime = DateTime.Now;
|
||||||
|
|
@ -301,8 +301,6 @@ namespace VideoAnalysisCore.Common
|
||||||
public async void InitChannel()
|
public async void InitChannel()
|
||||||
{
|
{
|
||||||
if (Redis is null) throw new Exception("redis未初始化");
|
if (Redis is null) throw new Exception("redis未初始化");
|
||||||
|
|
||||||
|
|
||||||
//处理之前程序结束前未能执行完的情况
|
//处理之前程序结束前未能执行完的情况
|
||||||
var oldTaskCount = Redis.LLen(RedisExpandKey.IDTask);
|
var oldTaskCount = Redis.LLen(RedisExpandKey.IDTask);
|
||||||
if (oldTaskCount > 0)
|
if (oldTaskCount > 0)
|
||||||
|
|
@ -378,7 +376,7 @@ namespace VideoAnalysisCore.Common
|
||||||
Console.WriteLine($"{DateTime.Now} =>服务端不接收任务");
|
Console.WriteLine($"{DateTime.Now} =>服务端不接收任务");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Task.Run(async () =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
lock (Redis)
|
lock (Redis)
|
||||||
{
|
{
|
||||||
|
|
@ -396,7 +394,6 @@ namespace VideoAnalysisCore.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -428,7 +425,7 @@ namespace VideoAnalysisCore.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="taskID"></param>
|
/// <param name="taskID"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> ClearTaskError(long taskID) =>await SetTaskError(taskID, string.Empty);
|
public async Task<bool> ClearTaskError(long taskID) => await SetTaskError(taskID, string.Empty);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 修改任务的错误信息
|
/// 修改任务的错误信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -437,8 +434,9 @@ namespace VideoAnalysisCore.Common
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> SetTaskError(long taskID, string? error)
|
public async Task<bool> SetTaskError(long taskID, string? error)
|
||||||
{
|
{
|
||||||
|
var vDB = AppCommon.Services.GetService<Repository<VideoTask>>();
|
||||||
Redis.HMSet(RedisExpandKey.Task(taskID), "ErrorMessage", error);
|
Redis.HMSet(RedisExpandKey.Task(taskID), "ErrorMessage", error);
|
||||||
return await videoTaskDB.AsUpdateable()
|
return await vDB.CopyNew().AsUpdateable()
|
||||||
.SetColumns(it => it.ErrorMessage == error)//SetColumns是可以叠加的 写2个就2个字段赋值
|
.SetColumns(it => it.ErrorMessage == error)//SetColumns是可以叠加的 写2个就2个字段赋值
|
||||||
.Where(it => it.Id == taskID)
|
.Where(it => it.Id == taskID)
|
||||||
.ExecuteCommandAsync() == 1;
|
.ExecuteCommandAsync() == 1;
|
||||||
|
|
@ -464,14 +462,11 @@ namespace VideoAnalysisCore.Common
|
||||||
{
|
{
|
||||||
Redis.HMSet(RedisExpandKey.Task(taskId), "LastEnum", key);
|
Redis.HMSet(RedisExpandKey.Task(taskId), "LastEnum", key);
|
||||||
Redis.HMSet(RedisExpandKey.Task(taskId), "Progress", 0);
|
Redis.HMSet(RedisExpandKey.Task(taskId), "Progress", 0);
|
||||||
lock (Redis)
|
var vDB = AppCommon.Services.GetService<Repository<VideoTask>>();
|
||||||
{
|
await vDB.CopyNew().AsUpdateable()
|
||||||
videoTaskDB.AsUpdateable()
|
|
||||||
.SetColumns(it => it.LastEnum == key)
|
.SetColumns(it => it.LastEnum == key)
|
||||||
.Where(it => it.Id == tID)
|
.Where(it => it.Id == tID)
|
||||||
.ExecuteCommand();
|
.ExecuteCommandAsync();
|
||||||
|
|
||||||
}
|
|
||||||
await action(taskId);
|
await action(taskId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -483,7 +478,7 @@ namespace VideoAnalysisCore.Common
|
||||||
Console.WriteLine("==============================================");
|
Console.WriteLine("==============================================");
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId);
|
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId);
|
||||||
if (i+1== tryCount)
|
if (i + 1 == tryCount)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace VideoAnalysisCore.Common
|
||||||
{
|
{
|
||||||
public class Repository<T> : SimpleClient<T> where T : class, new()
|
public class Repository<T> : SimpleClient<T> where T : class, new()
|
||||||
{
|
{
|
||||||
readonly Dictionary<Type, object?> CID= new Dictionary<Type, object?>();
|
readonly Dictionary<Type, object?> CID = new Dictionary<Type, object?>();
|
||||||
public Repository()
|
public Repository()
|
||||||
{
|
{
|
||||||
SwitchConnection();
|
SwitchConnection();
|
||||||
|
|
@ -23,17 +23,22 @@ namespace VideoAnalysisCore.Common
|
||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
if (CID.ContainsKey(t))
|
if (CID.ContainsKey(t))
|
||||||
{
|
{
|
||||||
base.Context = CID[t]!=null
|
base.Context = CID[t] != null
|
||||||
? DbScoped.Sugar.GetConnectionScope(CID[t])
|
? DbScoped.Sugar.GetConnectionScope(CID[t])
|
||||||
: DbScoped.Sugar;
|
: DbScoped.Sugar;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
var c = t.GetCustomAttribute<TenantAttribute>();
|
var c = t.GetCustomAttribute<TenantAttribute>();
|
||||||
if (!CID.ContainsKey(t))
|
if (!CID.ContainsKey(t))
|
||||||
CID.Add(t, c?.configId);
|
CID.Add(t, c?.configId);
|
||||||
base.Context = c != null
|
base.Context = c != null
|
||||||
? DbScoped.Sugar.GetConnectionScope(c.configId)
|
? DbScoped.Sugar.GetConnectionScope(c.configId)
|
||||||
: DbScoped.Sugar;
|
: DbScoped.Sugar;
|
||||||
|
//这个变量也要保证是线程安全的,尽量CopyNew在方法中使用
|
||||||
|
base.Context = base.Context.CopyNew();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.32" />
|
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.32" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
||||||
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
|
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
|
||||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.205" />
|
||||||
<PackageReference Include="UserCenter.Model" Version="1.3.5" />
|
<PackageReference Include="UserCenter.Model" Version="1.3.5" />
|
||||||
<PackageReference Include="Whisper.net" Version="1.5.0" />
|
<PackageReference Include="Whisper.net" Version="1.5.0" />
|
||||||
<PackageReference Include="Whisper.net.Runtime" Version="1.5.0" />
|
<PackageReference Include="Whisper.net.Runtime" Version="1.5.0" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue