hangfire测试

This commit is contained in:
橙子
2022-11-27 15:05:27 +08:00
parent d0770970f0
commit 49a9eb5460
10 changed files with 92 additions and 4 deletions

View File

@@ -602,6 +602,18 @@
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.HangfireStratJobTest">
<summary>
hangfireJob测试
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.HangfireStopJobTest">
<summary>
hangfireJob测试
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.TreeTest">
<summary>
树形结构构建测试

View File

@@ -101,7 +101,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[Log("用户模块", OperEnum.Update)]
public async Task<Result> Update(UserInfoDto userDto)
{
if (await _repository.IsAnyAsync(u => userDto.User.UserName.Equals(u.UserName) && !userDto.User.Id.Equals(u.Id)))
if (await _repository.IsAnyAsync(u => userDto.User.UserName!.Equals(u.UserName) && !userDto.User.Id.Equals(u.Id)))
{
return Result.Error("用户名已存在,修改失败!");
}
@@ -138,7 +138,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Error("密码为空,添加失败!");
}
if (await _repository.IsAnyAsync(u => userDto.User.UserName.Equals(u.UserName)))
if (await _repository.IsAnyAsync(u => userDto.User.UserName!.Equals(u.UserName)))
{
return Result.Error("用户已经存在,添加失败!");
}

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Hangfire;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Localization;
@@ -12,6 +13,7 @@ using Yi.Framework.Common.Const;
using Yi.Framework.Common.Models;
using Yi.Framework.Core;
using Yi.Framework.Interface;
using Yi.Framework.Job;
using Yi.Framework.Language;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
@@ -216,9 +218,36 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public async Task<Result> StopJob()
{
await _quartzInvoker.StopAsync(new Quartz.JobKey("test", "my"));
return Result.Success("http://localhost:19001/hangfire");
}
/// <summary>
/// hangfireJob测试
/// </summary>
/// <returns></returns>
[HttpGet]
public Result HangfireStratJobTest()
{
Dictionary<string, object> data = new Dictionary<string, object>()
{
{JobConst.method,"get" },
{JobConst.url,"https://www.baidu.com" }
};
RecurringJob.AddOrUpdate<HttpJob>(nameof(HttpJob),(Job)=>Job.Execute2(data), "*/5 * * * * ?");
return Result.Success("http://localhost:19001/hangfire");
}
/// <summary>
/// hangfireJob测试
/// </summary>
/// <returns></returns>
[HttpGet]
public Result HangfireStopJobTest()
{
RecurringJob.RemoveIfExists(nameof(HttpJob));
return Result.Success();
}
/// <summary>
/// 树形结构构建测试
/// </summary>

View File

@@ -18,6 +18,8 @@ using Yi.Framework.WebCore.LogExtend;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Mvc.Controllers;
using Yi.Framework.WebCore.AutoFacExtend;
using Hangfire;
using Hangfire.MemoryStorage;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddCommandLine(args);
@@ -78,6 +80,15 @@ builder.Services.AddSqlsugarServer(DbFiterExtend.Data);
//Quartz任务调度配置
#endregion
builder.Services.AddQuartzService();
builder.Services.AddHangfire(option =>
{
option.SetDataCompatibilityLevel(CompatibilityLevel.Version_170);//全局配置兼容版本,向下兼容
option.UseColouredConsoleLogProvider();//输出日志
option.UseSimpleAssemblyNameTypeSerializer();//使用简单程序集名称类型序列化程序
option.UseRecommendedSerializerSettings();//使用推荐的序列化配置
option.UseMemoryStorage();
});
builder.Services.AddHangfireServer();
#region
//AutoMapper注入
#endregion
@@ -85,7 +96,8 @@ builder.Services.AddAutoMapperService();
#region
//控制器+过滤器配置
#endregion
builder.Services.AddControllers(optios => {
builder.Services.AddControllers(optios =>
{
//注册全局
optios.Filters.Add<GlobalLogAttribute>();
}).AddJsonFileService();
@@ -228,6 +240,10 @@ app.UseDbSeedInitService();
#endregion
app.UseRedisSeedInitService();
app.UseHangfireDashboard();
app.UseEndpoints(endpoints =>
{
#region
@@ -235,6 +251,7 @@ app.UseEndpoints(endpoints =>
#endregion
endpoints.MapHub<MainHub>("/api/hub/main");
endpoints.MapControllers();
endpoints.MapHangfireDashboard();
});
//准备添加多租户