继续调整,手动开启定时任务相关逻辑代码,并处理相关bug
This commit is contained in:
@@ -145,7 +145,7 @@ public class OAuthService : IDynamicApiController, ITransient
|
||||
private readonly IMHandler _imHandler;
|
||||
|
||||
private readonly BackgroundService _backgroundService; //added by ly on 20230916
|
||||
private static CancellationTokenSource stopTimedTaskSvcCTS = new();
|
||||
private static CancellationTokenSource stopTimedTaskSvcCTS;
|
||||
private static Dictionary<string, Func<BackgroundService, bool>> _fetchPropValue = new();
|
||||
|
||||
|
||||
@@ -296,18 +296,26 @@ public class OAuthService : IDynamicApiController, ITransient
|
||||
//modify by ly on 20230918 登录成功后启动定时服务
|
||||
if (!userId.IsNullOrWhiteSpace())
|
||||
{
|
||||
|
||||
if (!_fetchPropValue.TryGetValue("IsStarted", out var action))
|
||||
{
|
||||
var isStartedProp = _backgroundService.GetType().GetProperty("IsStarted");
|
||||
var paramExp = Expression.Parameter(typeof(BackgroundService), "_backgroundSvc");
|
||||
var propExp = Expression.Property(Expression.ConvertChecked(paramExp, isStartedProp.DeclaringType), isStartedProp.GetGetMethod());
|
||||
var propExp = Expression.Property(Expression.ConvertChecked(paramExp, isStartedProp.DeclaringType), isStartedProp);
|
||||
var body = Expression.Lambda<Func<BackgroundService, Boolean>>(propExp, paramExp);
|
||||
action = body.Compile();
|
||||
_fetchPropValue["IsStarted"] = action;
|
||||
}
|
||||
if (!action?.Invoke(_backgroundService) ?? false)
|
||||
{
|
||||
await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token);
|
||||
stopTimedTaskSvcCTS = new();
|
||||
try
|
||||
{
|
||||
_backgroundService.StartAsync(stopTimedTaskSvcCTS.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,8 +419,11 @@ public class OAuthService : IDynamicApiController, ITransient
|
||||
public async Task Logout([FromQuery] string ticket)
|
||||
{
|
||||
//modify by ly on 20230918
|
||||
stopTimedTaskSvcCTS ??= new();
|
||||
await _backgroundService.StopAsync(stopTimedTaskSvcCTS.Token);
|
||||
stopTimedTaskSvcCTS.Cancel();
|
||||
//stopTimedTaskSvcCTS.Dispose();
|
||||
|
||||
UserManager.AsscessToken = string.Empty;
|
||||
|
||||
var tenantId = _userManager.TenantId ?? "default";
|
||||
|
||||
Reference in New Issue
Block a user