diff --git a/VideoAnalysisCore/Common/RedisExpand.cs b/VideoAnalysisCore/Common/RedisExpand.cs index de5aaa6..11fa01d 100644 --- a/VideoAnalysisCore/Common/RedisExpand.cs +++ b/VideoAnalysisCore/Common/RedisExpand.cs @@ -113,41 +113,40 @@ namespace VideoAnalysisCore.Common public void Init() { var SubscribeList = RedisManager.SubscribeList; - SubscribeList.Add(RedisChannelEnum.下载文件, (task) => + SubscribeList.Add(RedisChannelEnum.下载文件, async (task) => { using var scope = AppCommon.Services?.CreateScope(); if (scope is null || scope.ServiceProvider.GetService() is null) throw new Exception("DownloadFile 未注入"); else - return scope.ServiceProvider.GetService()?.RunTask(task) ?? Task.CompletedTask; + await scope.ServiceProvider.GetService()?.RunTask(task) ; }); SubscribeList.Add(RedisChannelEnum.分离音频, FFMPGE.RunAsync); SubscribeList.Add(RedisChannelEnum.解析字幕, senseVoice.RunTask); //SubscribeList.Add(RedisChannelEnum.解析说话人,Speaker.Run); - SubscribeList.Add(RedisChannelEnum.AI课程类型, - (task) => + SubscribeList.Add(RedisChannelEnum.AI课程类型, async (task) => { using var scope = AppCommon.Services?.CreateScope(); if (scope is null || scope.ServiceProvider.GetService() is null) throw new Exception("IBserGPT 未注入"); else - return scope.ServiceProvider.GetService()?.GetVideoType(task) ?? Task.CompletedTask; + await scope.ServiceProvider.GetService()?.GetVideoType(task); }); - SubscribeList.Add(RedisChannelEnum.AI模型分析, (task) => + SubscribeList.Add(RedisChannelEnum.AI模型分析, async (task) => { using var scope = AppCommon.Services?.CreateScope(); if (scope is null || scope.ServiceProvider.GetService() is null) throw new Exception("IBserGPT 未注入"); else - return scope.ServiceProvider.GetService()?.GetKnow(task) ?? Task.CompletedTask; + await scope.ServiceProvider?.GetService()?.GetKnow(task); }); - SubscribeList.Add(RedisChannelEnum.AI分析试题, (task) => + SubscribeList.Add(RedisChannelEnum.AI分析试题, async (task) => { using var scope = AppCommon.Services?.CreateScope(); if (scope is null || scope.ServiceProvider.GetService() is null) throw new Exception("IBserGPT 未注入"); else - return scope.ServiceProvider.GetService()?.GetVideoQuestion(task) ?? Task.CompletedTask; + await scope.ServiceProvider?.GetService()?.GetVideoQuestion(task); }); SubscribeList.Add(RedisChannelEnum.结束任务, redisManager.TaskEnd); @@ -314,7 +313,8 @@ namespace VideoAnalysisCore.Common if (oldTaskCount > 0) { 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) { _ = Task.Run(async () => diff --git a/VideoAnalysisCore/Common/Repository.cs b/VideoAnalysisCore/Common/Repository.cs index bcab5d1..490f107 100644 --- a/VideoAnalysisCore/Common/Repository.cs +++ b/VideoAnalysisCore/Common/Repository.cs @@ -26,7 +26,6 @@ namespace VideoAnalysisCore.Common base.Context = CID[t] != null ? DbScoped.Sugar.GetConnectionScope(CID[t]) : DbScoped.Sugar; - return; } else { @@ -36,9 +35,9 @@ namespace VideoAnalysisCore.Common base.Context = c != null ? DbScoped.Sugar.GetConnectionScope(c.configId) : DbScoped.Sugar; - //这个变量也要保证是线程安全的,尽量CopyNew在方法中使用 - base.Context = base.Context.CopyNew(); } + //这个变量也要保证是线程安全的,尽量CopyNew在方法中使用 + base.Context = base.Context.CopyNew(); } } }