40 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
| using Hangfire;
 | ||
| using Hangfire.Dashboard;
 | ||
| using IRaCIS.Application.Services.BackGroundJob;
 | ||
| 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() }
 | ||
| 
 | ||
|             });
 | ||
| 
 | ||
|             #region hangfire
 | ||
|             //// 延迟任务执行  1秒之后执行  有时启动没运行  换成添加到队列中
 | ||
|             //BackgroundJob.Schedule<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus(), TimeSpan.FromSeconds(1));
 | ||
|             ////添加到后台任务队列,
 | ||
|             //BackgroundJob.Enqueue<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus());
 | ||
| 
 | ||
|             //周期性任务,1天执行一次
 | ||
|             RecurringJob.AddOrUpdate<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus(), Cron.Daily);
 | ||
| 
 | ||
|             #endregion
 | ||
| 
 | ||
|         }
 | ||
|     }
 | ||
| }
 |