1
0

113/03/12

This commit is contained in:
2024-03-12 11:57:08 +08:00
parent 634172304f
commit 0c512bcd82
12 changed files with 308 additions and 29 deletions

View File

@@ -1,5 +1,7 @@
using Hangfire;
using Hangfire.Dashboard;
using Hangfire.Storage.SQLite;
using HangfireExample.WebService.Filters;
namespace HangfireExample.WebService.Extensions
{
@@ -18,13 +20,37 @@ namespace HangfireExample.WebService.Extensions
// 將 Hangfire 加入服務,使用 SQLite 作為儲存區
services.AddHangfire(configuration => configuration
.UseSQLiteStorage("HangfireExample.db"));
// 將 Hangfire Server 加入服務
services.AddHangfireServer(options =>
{
// 指定 Hangfire Server 的名稱
options.ServerName = "HangfireExample";
// 指定 Hangfire Server 執行佇列的 Tags
options.Queues = ["default", "wb",];
});
return services;
}
public static WebApplication UseHangfireDashboard(this WebApplication app, IConfiguration configuration)
{
// HangfireDashboard 預設路由為 /Hangfire
app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"));
// Hangfire Dashboard 預設路由為 /Hangfire
app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"), new DashboardOptions
{
Authorization = [new DashboardAuthorizationFilter()],
// 指定 Dashboard 指定讀取,不能操作,如重新執行、再次加入排程與刪除任務等
IsReadOnlyFunc = (DashboardContext context) => true,
// 指定 Back to site 的連結
AppPath = "/swagger",
});
// 設定第二資料來源的 Dashboard
//app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"), new DashboardOptions
//{
// Authorization = [new DashboardAuthorizationFilter()],
// // 指定 Dashboard 指定讀取,不能操作,如重新執行、再次加入排程與刪除任務等
// IsReadOnlyFunc = (DashboardContext context) => true,
// // 指定 Back to site 的連結
// AppPath = "/swagger",
//}, new SQLiteStorage("HangfireExample2.db"));
return app;
}
}