From 5a6dc4961508c5cdfc844d62b3ed73b1fba94a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Mon, 27 Oct 2025 10:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=20=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=BB=E5=8A=A1=E6=97=B6=20=E6=B2=A1?= =?UTF-8?q?=E4=BD=BF=E7=94=A8await=E7=AD=89=E5=BE=85=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E=E6=8E=A5=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VideoAnalysisCore/Common/RedisExpand.cs | 20 ++++++++++---------- VideoAnalysisCore/Common/Repository.cs | 5 ++--- 2 files changed, 12 insertions(+), 13 deletions(-) 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(); } } }