优化 当前消费中的队列缓存

修改 sql仓储层的注入
This commit is contained in:
小肥羊 2025-09-26 15:11:39 +08:00
parent 6015245d78
commit 94cde3af70
6 changed files with 23 additions and 17 deletions

View File

@ -120,7 +120,7 @@
"LastEnvName": "10楼刀片机", "LastEnvName": "10楼刀片机",
"RemoveDaysFromPublished": "10", "RemoveDaysFromPublished": "10",
"WorkDir": "/home/heyang/", "WorkDir": "/home/heyang/",
"Volume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile", "Volume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/mnt/2tb/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
"Other": "-e va_args=\"\"", "Other": "-e va_args=\"\"",
"EnvPairList": [ "EnvPairList": [
{ {
@ -129,7 +129,7 @@
"LinuxEnvParam": null, "LinuxEnvParam": null,
"DockerPort": "9040", "DockerPort": "9040",
"DockerEnvName": "", "DockerEnvName": "",
"DockerVolume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile", "DockerVolume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/mnt/2tb/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
"DockerOther": "-e va_args=\"\"" "DockerOther": "-e va_args=\"\""
}, },
{ {

View File

@ -180,7 +180,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
.ExecuteCommandAsync(); .ExecuteCommandAsync();
await RedisExpand.Redis.HMSetAsync(RedisExpandKey.Task(task), "Captions", res); await RedisExpand.Redis.HMSetAsync(RedisExpandKey.Task(task), "Captions", res);
//分析完成视频字幕后继续接收任务 //分析完成视频字幕后继续接收任务
RedisExpand.NewTaskAsync(); RedisExpand.NewTask();
} }
return res; return res;
} }

View File

@ -44,7 +44,7 @@ namespace VideoAnalysisCore.Common.Expand
DbType = s.SqlType, DbType = s.SqlType,
IsAutoCloseConnection = true IsAutoCloseConnection = true
})); }));
services.AddTransient(typeof(Repository<>)); services.AddScoped(typeof(Repository<>));
//注入SqlSugar 主库 //注入SqlSugar 主库
services.AddSqlSugar(dbList); services.AddSqlSugar(dbList);

View File

@ -297,20 +297,23 @@ namespace VideoAnalysisCore.Common
/// <summary> /// <summary>
/// 开始接收新任务 /// 开始接收新任务
/// </summary> /// </summary>
public static void RestartTaskAsync() public static void RestartTask()
{ {
StopTask = false; StopTask = false;
NewTaskAsync(); NewTask();
} }
/// <summary> /// <summary>
/// 重新执行新任务 /// 重新执行新任务
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static async void NewTaskAsync() public static void NewTask()
{ {
// 取消 消费机的任务订阅 // 取消 消费机的任务订阅
if (StopTask) if (StopTask)
{
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-------------> 接收任务已经暂停 ");
return; return;
}
ReceivingTaskAsync(); ReceivingTaskAsync();
} }
@ -374,7 +377,7 @@ namespace VideoAnalysisCore.Common
Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.StackTrace);
Console.WriteLine("=============================================="); Console.WriteLine("==============================================");
//清除失败任务 重新接收任务 //清除失败任务 重新接收任务
NewTaskAsync(); NewTask();
} }
return await SetTaskError(taskID, error); return await SetTaskError(taskID, error);
} }

View File

@ -24,16 +24,16 @@ namespace VideoAnalysisCore.Common
if (CID.ContainsKey(t)) if (CID.ContainsKey(t))
{ {
base.Context = CID[t]!=null base.Context = CID[t]!=null
? DbScoped.Sugar.GetConnectionScope(CID[t]) ? DbScoped.SugarScope.GetConnectionScope(CID[t])
: DbScoped.Sugar; : DbScoped.SugarScope;
return; return;
} }
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.SugarScope.GetConnectionScope(c.configId)
: DbScoped.Sugar; : DbScoped.SugarScope;
} }
} }
} }

View File

@ -76,13 +76,16 @@ namespace VideoAnalysisCore.Controllers
/// <summary> /// <summary>
/// ³õʼ»¯Ö÷¿â±í /// ³õʼ»¯Ö÷¿â±í
/// </summary> /// </summary>
/// <param name="url">文件流</param> /// <param name="task">是否执行任务</param>
/// <returns></returns> /// <returns></returns>
[HttpGet(Name = "tets1")] [HttpGet(Name = "StartTask")]
public IActionResult tets1(string task) public IActionResult StartTask(bool task)
{ {
var courseArr = courseInfoDB.AsQueryable().ToArray(); if(task)
return Ok(courseArr); RedisExpand.RestartTask();
else
RedisExpand.StopTaskAsync();
return Ok();
} }
/// <summary> /// <summary>
/// ÓïÒôʶ±ð /// ÓïÒôʶ±ð