1
0

新增方法練習顯示處理進度

This commit is contained in:
2024-03-18 10:43:42 +08:00
parent ea4e5da703
commit e55b957028
6 changed files with 52 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
using Hangfire;
using Hangfire.Console;
using Hangfire.Dashboard;
using Hangfire.PerformContextAccessor;
using Hangfire.Storage.SQLite;
using HangfireExample.WebService.Filters;
@@ -17,9 +19,13 @@ namespace HangfireExample.WebService.Extensions
/// <returns></returns>
public static IServiceCollection AddHangfire(this IServiceCollection services)
{
// 將 Hangfire 處理序存取加入服務
services.AddHangfirePerformContextAccessor();
// 將 Hangfire 加入服務,使用 SQLite 作為儲存區
services.AddHangfire(configuration => configuration
.UseSQLiteStorage("HangfireExample.db"));
.UseSQLiteStorage("HangfireExample.db")
.UsePerformContextAccessorFilter()
.UseConsole());
// 將 Hangfire Server 加入服務
services.AddHangfireServer(options =>
{
@@ -38,7 +44,7 @@ namespace HangfireExample.WebService.Extensions
{
Authorization = [new DashboardAuthorizationFilter()],
// 指定 Dashboard 指定讀取,不能操作,如重新執行、再次加入排程與刪除任務等
IsReadOnlyFunc = (DashboardContext context) => true,
IsReadOnlyFunc = (DashboardContext context) => false,
// 指定 Back to site 的連結
AppPath = "/swagger",
});