irc-netcore-api/IRaCIS.Core.API/_PipelineExtensions/HangfireConfig.cs

64 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Hangfire;
using Hangfire.Dashboard;
using Hangfire.Dashboard.BasicAuthorization;
using IRaCIS.Application.Services.BackGroundJob;
using IRaCIS.Core.API.Filter;
using IRaCIS.Core.Application.Helper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace IRaCIS.Core.API
{
public static class HangfireConfig
{
public static void UseHangfireConfig(this IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHangfireDashboard("/api/hangfire", new DashboardOptions()
{
//直接访问没有带token 获取不到用户身份信息,所以这种自定义授权暂时没法使用
//Authorization = new[] { new hangfireAuthorizationFilter() }
//本地请求 才能看
//Authorization = new[] { new LocalRequestsOnlyAuthorizationFilter() }
Authorization = new BasicAuthAuthorizationFilter[] {
new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions(){
SslRedirect=false,
RequireSsl=false,
Users=new BasicAuthAuthorizationUser[]{
new BasicAuthAuthorizationUser(){
Login="admin",
PasswordClear="test",
}
}
})
}
});
#region hangfire
HangfireJobHelper.ImmediatelyOnceOnlyJob<IIRaCISHangfireJob>( t => t.InitHangfireJobTaskAsync() );
//// 延迟任务执行 1秒之后执行 有时启动没运行 换成添加到队列中
//BackgroundJob.Schedule<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus(), TimeSpan.FromSeconds(1));
////添加到后台任务队列,
//BackgroundJob.Enqueue<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus());
//周期性任务1天执行一次
//RecurringJob.AddOrUpdate<IIRaCISCacheHangfireJob>(t => t.ProjectStartCache(), Cron.Daily);
#endregion
}
}
}