hangfire测试
This commit is contained in:
@@ -602,6 +602,18 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.TreeTest">
|
||||||
<summary>
|
<summary>
|
||||||
树形结构构建测试
|
树形结构构建测试
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
[Log("用户模块", OperEnum.Update)]
|
[Log("用户模块", OperEnum.Update)]
|
||||||
public async Task<Result> Update(UserInfoDto userDto)
|
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("用户名已存在,修改失败!");
|
return Result.Error("用户名已存在,修改失败!");
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
{
|
{
|
||||||
return Result.Error("密码为空,添加失败!");
|
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("用户已经存在,添加失败!");
|
return Result.Error("用户已经存在,添加失败!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Hangfire;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
@@ -12,6 +13,7 @@ using Yi.Framework.Common.Const;
|
|||||||
using Yi.Framework.Common.Models;
|
using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.Core;
|
using Yi.Framework.Core;
|
||||||
using Yi.Framework.Interface;
|
using Yi.Framework.Interface;
|
||||||
|
using Yi.Framework.Job;
|
||||||
using Yi.Framework.Language;
|
using Yi.Framework.Language;
|
||||||
using Yi.Framework.Model.Models;
|
using Yi.Framework.Model.Models;
|
||||||
using Yi.Framework.Repository;
|
using Yi.Framework.Repository;
|
||||||
@@ -216,9 +218,36 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
public async Task<Result> StopJob()
|
public async Task<Result> StopJob()
|
||||||
{
|
{
|
||||||
await _quartzInvoker.StopAsync(new Quartz.JobKey("test", "my"));
|
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();
|
return Result.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 树形结构构建测试
|
/// 树形结构构建测试
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ using Yi.Framework.WebCore.LogExtend;
|
|||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Yi.Framework.WebCore.AutoFacExtend;
|
using Yi.Framework.WebCore.AutoFacExtend;
|
||||||
|
using Hangfire;
|
||||||
|
using Hangfire.MemoryStorage;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.Configuration.AddCommandLine(args);
|
builder.Configuration.AddCommandLine(args);
|
||||||
@@ -78,6 +80,15 @@ builder.Services.AddSqlsugarServer(DbFiterExtend.Data);
|
|||||||
//Quartz<74><7A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//Quartz<74><7A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
#endregion
|
#endregion
|
||||||
builder.Services.AddQuartzService();
|
builder.Services.AddQuartzService();
|
||||||
|
builder.Services.AddHangfire(option =>
|
||||||
|
{
|
||||||
|
option.SetDataCompatibilityLevel(CompatibilityLevel.Version_170);//ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC>ݰ汾<DDB0><E6B1BE><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
|
||||||
|
option.UseColouredConsoleLogProvider();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||||
|
option.UseSimpleAssemblyNameTypeSerializer();//ʹ<>ü<C3BC><F2B5A5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
option.UseRecommendedSerializerSettings();//ʹ<><CAB9><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
option.UseMemoryStorage();
|
||||||
|
});
|
||||||
|
builder.Services.AddHangfireServer();
|
||||||
#region
|
#region
|
||||||
//AutoMapperע<72><D7A2>
|
//AutoMapperע<72><D7A2>
|
||||||
#endregion
|
#endregion
|
||||||
@@ -85,7 +96,8 @@ builder.Services.AddAutoMapperService();
|
|||||||
#region
|
#region
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
#endregion
|
#endregion
|
||||||
builder.Services.AddControllers(optios => {
|
builder.Services.AddControllers(optios =>
|
||||||
|
{
|
||||||
//ע<><D7A2>ȫ<EFBFBD><C8AB>
|
//ע<><D7A2>ȫ<EFBFBD><C8AB>
|
||||||
optios.Filters.Add<GlobalLogAttribute>();
|
optios.Filters.Add<GlobalLogAttribute>();
|
||||||
}).AddJsonFileService();
|
}).AddJsonFileService();
|
||||||
@@ -228,6 +240,10 @@ app.UseDbSeedInitService();
|
|||||||
#endregion
|
#endregion
|
||||||
app.UseRedisSeedInitService();
|
app.UseRedisSeedInitService();
|
||||||
|
|
||||||
|
app.UseHangfireDashboard();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
#region
|
#region
|
||||||
@@ -235,6 +251,7 @@ app.UseEndpoints(endpoints =>
|
|||||||
#endregion
|
#endregion
|
||||||
endpoints.MapHub<MainHub>("/api/hub/main");
|
endpoints.MapHub<MainHub>("/api/hub/main");
|
||||||
endpoints.MapControllers();
|
endpoints.MapControllers();
|
||||||
|
endpoints.MapHangfireDashboard();
|
||||||
});
|
});
|
||||||
|
|
||||||
//<><D7BC><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6>⻧
|
//<><D7BC><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6>⻧
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" />
|
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" />
|
||||||
<PackageReference Include="Consul" Version="1.6.10.3" />
|
<PackageReference Include="Consul" Version="1.6.10.3" />
|
||||||
<PackageReference Include="CSRedisCore" Version="3.6.9" />
|
<PackageReference Include="CSRedisCore" Version="3.6.9" />
|
||||||
|
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.32" />
|
||||||
|
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
|
||||||
@@ -22,4 +24,8 @@
|
|||||||
<ProjectReference Include="..\Yi.Framework.Task\Yi.Framework.Job.csproj" />
|
<ProjectReference Include="..\Yi.Framework.Task\Yi.Framework.Job.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Hangfire\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -36,6 +36,30 @@ namespace Yi.Framework.Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_logger.LogWarning("定时任务开始调度:" + nameof(HttpJob) + ":" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + $":访问地址为:{url},结果为:{data}");
|
||||||
|
Console.WriteLine($"结果:{data}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Execute2(Dictionary<string,object> dic)
|
||||||
|
{
|
||||||
|
return Task.Run(async () =>
|
||||||
|
{
|
||||||
|
//var jobData = context.JobDetail.JobDataMap;
|
||||||
|
string method = dic[Common.Const.JobConst.method].ToString();
|
||||||
|
string url = dic[Common.Const.JobConst.url].ToString();
|
||||||
|
string data = "异常!";
|
||||||
|
switch (method)
|
||||||
|
{
|
||||||
|
case "post":
|
||||||
|
data = await Common.Helper.HttpHelper.Post(url);
|
||||||
|
break;
|
||||||
|
case "get":
|
||||||
|
data = await Common.Helper.HttpHelper.Get(url);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_logger.LogWarning("定时任务开始调度:" + nameof(HttpJob) + ":" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + $":访问地址为:{url},结果为:{data}");
|
_logger.LogWarning("定时任务开始调度:" + nameof(HttpJob) + ":" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + $":访问地址为:{url},结果为:{data}");
|
||||||
Console.WriteLine($"结果:{data}");
|
Console.WriteLine($"结果:{data}");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user