修复 执行部分任务时 没使用await等待导致的数据库连接异常
This commit is contained in:
parent
0a654c72ed
commit
5a6dc49615
|
|
@ -113,41 +113,40 @@ namespace VideoAnalysisCore.Common
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
var SubscribeList = RedisManager.SubscribeList;
|
var SubscribeList = RedisManager.SubscribeList;
|
||||||
SubscribeList.Add(RedisChannelEnum.下载文件, (task) =>
|
SubscribeList.Add(RedisChannelEnum.下载文件, async (task) =>
|
||||||
{
|
{
|
||||||
using var scope = AppCommon.Services?.CreateScope();
|
using var scope = AppCommon.Services?.CreateScope();
|
||||||
if (scope is null || scope.ServiceProvider.GetService<DownloadFile>() is null)
|
if (scope is null || scope.ServiceProvider.GetService<DownloadFile>() is null)
|
||||||
throw new Exception("DownloadFile 未注入");
|
throw new Exception("DownloadFile 未注入");
|
||||||
else
|
else
|
||||||
return scope.ServiceProvider.GetService<DownloadFile>()?.RunTask(task) ?? Task.CompletedTask;
|
await scope.ServiceProvider.GetService<DownloadFile>()?.RunTask(task) ;
|
||||||
});
|
});
|
||||||
SubscribeList.Add(RedisChannelEnum.分离音频, FFMPGE.RunAsync);
|
SubscribeList.Add(RedisChannelEnum.分离音频, FFMPGE.RunAsync);
|
||||||
SubscribeList.Add(RedisChannelEnum.解析字幕, senseVoice.RunTask);
|
SubscribeList.Add(RedisChannelEnum.解析字幕, senseVoice.RunTask);
|
||||||
//SubscribeList.Add(RedisChannelEnum.解析说话人,Speaker.Run);
|
//SubscribeList.Add(RedisChannelEnum.解析说话人,Speaker.Run);
|
||||||
SubscribeList.Add(RedisChannelEnum.AI课程类型,
|
SubscribeList.Add(RedisChannelEnum.AI课程类型, async (task) =>
|
||||||
(task) =>
|
|
||||||
{
|
{
|
||||||
using var scope = AppCommon.Services?.CreateScope();
|
using var scope = AppCommon.Services?.CreateScope();
|
||||||
if (scope is null || scope.ServiceProvider.GetService<IBserGPT>() is null)
|
if (scope is null || scope.ServiceProvider.GetService<IBserGPT>() is null)
|
||||||
throw new Exception("IBserGPT 未注入");
|
throw new Exception("IBserGPT 未注入");
|
||||||
else
|
else
|
||||||
return scope.ServiceProvider.GetService<IBserGPT>()?.GetVideoType(task) ?? Task.CompletedTask;
|
await scope.ServiceProvider.GetService<IBserGPT>()?.GetVideoType(task);
|
||||||
});
|
});
|
||||||
SubscribeList.Add(RedisChannelEnum.AI模型分析, (task) =>
|
SubscribeList.Add(RedisChannelEnum.AI模型分析, async (task) =>
|
||||||
{
|
{
|
||||||
using var scope = AppCommon.Services?.CreateScope();
|
using var scope = AppCommon.Services?.CreateScope();
|
||||||
if (scope is null || scope.ServiceProvider.GetService<IBserGPT>() is null)
|
if (scope is null || scope.ServiceProvider.GetService<IBserGPT>() is null)
|
||||||
throw new Exception("IBserGPT 未注入");
|
throw new Exception("IBserGPT 未注入");
|
||||||
else
|
else
|
||||||
return scope.ServiceProvider.GetService<IBserGPT>()?.GetKnow(task) ?? Task.CompletedTask;
|
await scope.ServiceProvider?.GetService<IBserGPT>()?.GetKnow(task);
|
||||||
});
|
});
|
||||||
SubscribeList.Add(RedisChannelEnum.AI分析试题, (task) =>
|
SubscribeList.Add(RedisChannelEnum.AI分析试题, async (task) =>
|
||||||
{
|
{
|
||||||
using var scope = AppCommon.Services?.CreateScope();
|
using var scope = AppCommon.Services?.CreateScope();
|
||||||
if (scope is null || scope.ServiceProvider.GetService<IBserGPT>() is null)
|
if (scope is null || scope.ServiceProvider.GetService<IBserGPT>() is null)
|
||||||
throw new Exception("IBserGPT 未注入");
|
throw new Exception("IBserGPT 未注入");
|
||||||
else
|
else
|
||||||
return scope.ServiceProvider.GetService<IBserGPT>()?.GetVideoQuestion(task) ?? Task.CompletedTask;
|
await scope.ServiceProvider?.GetService<IBserGPT>()?.GetVideoQuestion(task);
|
||||||
});
|
});
|
||||||
SubscribeList.Add(RedisChannelEnum.结束任务, redisManager.TaskEnd);
|
SubscribeList.Add(RedisChannelEnum.结束任务, redisManager.TaskEnd);
|
||||||
|
|
||||||
|
|
@ -314,7 +313,8 @@ namespace VideoAnalysisCore.Common
|
||||||
if (oldTaskCount > 0)
|
if (oldTaskCount > 0)
|
||||||
{
|
{
|
||||||
var oldTaskArr = Redis.LRange(RedisExpandKey.IDTask, 0, oldTaskCount);
|
var oldTaskArr = Redis.LRange(RedisExpandKey.IDTask, 0, oldTaskCount);
|
||||||
Redis.LTrim(RedisExpandKey.IDTask, 1, 0);//删除 redis 列表
|
//不自动清理未完成任务 等待执行完毕/失败后自动清理
|
||||||
|
//Redis.LTrim(RedisExpandKey.IDTask, 1, 0);//删除 redis 列表
|
||||||
foreach (var oldTask in oldTaskArr)
|
foreach (var oldTask in oldTaskArr)
|
||||||
{
|
{
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ namespace VideoAnalysisCore.Common
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -36,9 +35,9 @@ namespace VideoAnalysisCore.Common
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
//这个变量也要保证是线程安全的,尽量CopyNew在方法中使用
|
||||||
|
base.Context = base.Context.CopyNew();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue