From b37d940ed139d9ad7daa4bd5695947f0036e9da7 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 22 Mar 2024 14:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=BA=E7=A8=8B=E5=BC=8F=E7=A2=BC=E5=8D=80?= =?UTF-8?q?=E5=A1=8A=E5=8A=A0=E4=B8=8A=E8=AA=9E=E8=A8=80=E6=8C=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6ba5c90..3192bb0 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Hangfire 會將所有相關資訊會被序列化後保存到儲存區,如類 資料來源日期: 2024/03/12 -``` +```C# // Hangfire 1.8 GlobalConfiguration .Configuration @@ -80,7 +80,7 @@ GlobalConfiguration 啟動 Hangfire 伺服器 -``` +```C# services.AddHangfireServer(); ``` @@ -88,7 +88,7 @@ services.AddHangfireServer(); 開啟 Dashboard 功能 -``` +```C# app.UseHangfireDashboard(); ``` @@ -96,7 +96,7 @@ app.UseHangfireDashboard(); 設定自定義驗證 -``` +```C# app.UseHangfireDashboard("hangfire", new DashboardOptions { Authorization = [new DashboardAuthorizationFilter()], @@ -107,7 +107,7 @@ app.UseHangfireDashboard("hangfire", new DashboardOptions 設定 UI 為 ReadOnly -``` +```C# app.UseHangfireDashboard("hangfire", new DashboardOptions { IsReadOnlyFunc = (DashboardContext context) => true, @@ -118,7 +118,7 @@ app.UseHangfireDashboard("hangfire", new DashboardOptions 修改 Dashboard UI 的預設根路由 -``` +```C# app.UseHangfireDashboard("hangfire"); ``` @@ -126,7 +126,7 @@ app.UseHangfireDashboard("hangfire"); 修改返回按鈕的路由 -``` +```C# app.UseHangfireDashboard("hangfire", new DashboardOptions { AppPath = "/swagger", // 導向到 Swagger UI @@ -139,7 +139,7 @@ app.UseHangfireDashboard("hangfire", new DashboardOptions 設定不同資料來源的 Dashboard -``` +```C# app.UseHangfireDashboard(configuration.GetValue("DashboardRoot"), new DashboardOptions { Authorization = [new DashboardAuthorizationFilter()], @@ -156,13 +156,13 @@ app.UseHangfireDashboard(configuration.GetValue("DashboardRoot"), new Da * Fire-and-Forget jobs: 將任務丟入執行佇列,直接執行 -``` +```C# BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-Forget")); ``` * Delayed jobs: 延遲指定時間後,將任務丟入執行佇列 -``` +```C# BackgroundJob.Schedule(() => Console.WriteLine("Delayed"), TimeSpan.FromDays(1)); ``` @@ -239,7 +239,7 @@ Cron Expression [測試](https://crontab.guru/) -``` +```C# RecurringJob.AddOrUpdate("job_id", () => Console.Write("Recurring By CRON"), Cron.Daily); RecurringJob.AddOrUpdate("job_id", () => Console.Write("Recurring By CRON expressions"), "* 0/1 * * ? *"); @@ -247,20 +247,20 @@ RecurringJob.AddOrUpdate("job_id", () => Console.Write("Recurring By CRON expres 移除已存在的排程任務 -``` +```C# RecurringJob.RemoveIfExists("job_id"); ``` 手動觸發已存在的排程任務 -``` +```C# RecurringJob.Trigger("job_id"); ``` * Continuations: 指定的任務完成後,才丟入執行佇列 -``` +```C# var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-Forget")); BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations")); @@ -272,7 +272,7 @@ BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations")); 使用 IPerformContextAccessor 從 Hangfire 的 PerformContext 取得進度管理的元件後,透過 Console 提供的擴充輸出到 GUI 管理介面。 -``` +```shell NUGET INSTALL Bonura.Hangfire.PerformContextAccessor -Version 1.3.3 NUGET INSTALL Hangfire.Console -Version 1.4.3 @@ -282,7 +282,7 @@ NUGET INSTALL Hangfire.Console -Version 1.4.3 Console 套件同時也提供格式化輸出字串的功能。 -``` +```C# // 取得 Hangfire 的進程管理 var bar = context.WriteProgressBar();