修复定时任务不能运行

This commit is contained in:
yubaolee
2021-02-04 13:51:39 +08:00
parent 24f8eaf8c0
commit ecc32d4173
2 changed files with 29 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using Infrastructure; using Infrastructure;
using Infrastructure.Cache; using Infrastructure.Cache;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@@ -37,5 +38,17 @@ namespace OpenAuth.App.Test
var result = app.QueryLocalHandlers(); var result = app.QueryLocalHandlers();
Console.WriteLine(JsonHelper.Instance.Serialize(result)); Console.WriteLine(JsonHelper.Instance.Serialize(result));
} }
[Test]
public void ChangeStatus()
{
var app = _autofacServiceProvider.GetService<OpenJobApp>();
app.ChangeJobStatus(new ChangeJobStatusReq
{
Id = "f40fe48d-71a4-4f47-b324-6178d97abfb9",
Status = 1
});
Thread.Sleep(60000);
}
} }
} }

View File

@@ -40,22 +40,22 @@ namespace OpenAuth.Repository
//初始化多租户信息根据租户id调整数据库 //初始化多租户信息根据租户id调整数据库
private void InitTenant(DbContextOptionsBuilder optionsBuilder) private void InitTenant(DbContextOptionsBuilder optionsBuilder)
{ {
if (_httpContextAccessor == null || _httpContextAccessor.HttpContext == null) string tenantId = "OpenAuthDBContext";
{
return;
}
//读取多租户ID if (_httpContextAccessor != null && _httpContextAccessor.HttpContext != null)
string tenantId = _httpContextAccessor.HttpContext.Request.Query[Define.TENANT_ID];
if (string.IsNullOrEmpty(tenantId))
{ {
tenantId = _httpContextAccessor.HttpContext.Request.Headers[Define.TENANT_ID]; //读取多租户ID
} var httpTenantId = _httpContextAccessor.HttpContext.Request.Query[Define.TENANT_ID];
if (string.IsNullOrEmpty(httpTenantId))
{
httpTenantId = _httpContextAccessor.HttpContext.Request.Headers[Define.TENANT_ID];
}
//如果没有租户id或租户用的是默认的OpenAuthDBContext,则不做任何调整 //如果没有租户id或租户用的是默认的OpenAuthDBContext,则不做任何调整
if (string.IsNullOrEmpty(tenantId)) if (!string.IsNullOrEmpty(httpTenantId))
{ {
tenantId = "OpenAuthDBContext"; tenantId = httpTenantId;
}
} }
string connect = _configuration.GetConnectionString(tenantId); string connect = _configuration.GetConnectionString(tenantId);