1
0

為程式碼區塊加上語言指定

This commit is contained in:
2024-03-22 14:16:19 +08:00
parent 78b4bc3792
commit b37d940ed1

View File

@@ -46,7 +46,7 @@ Hangfire 會將所有相關資訊會被序列化後保存到儲存區,如類
資料來源日期: 2024/03/12 資料來源日期: 2024/03/12
``` ```C#
// Hangfire 1.8 // Hangfire 1.8
GlobalConfiguration GlobalConfiguration
.Configuration .Configuration
@@ -80,7 +80,7 @@ GlobalConfiguration
啟動 Hangfire 伺服器 啟動 Hangfire 伺服器
``` ```C#
services.AddHangfireServer(); services.AddHangfireServer();
``` ```
@@ -88,7 +88,7 @@ services.AddHangfireServer();
開啟 Dashboard 功能 開啟 Dashboard 功能
``` ```C#
app.UseHangfireDashboard(); app.UseHangfireDashboard();
``` ```
@@ -96,7 +96,7 @@ app.UseHangfireDashboard();
設定自定義驗證 設定自定義驗證
``` ```C#
app.UseHangfireDashboard("hangfire", new DashboardOptions app.UseHangfireDashboard("hangfire", new DashboardOptions
{ {
Authorization = [new DashboardAuthorizationFilter()], Authorization = [new DashboardAuthorizationFilter()],
@@ -107,7 +107,7 @@ app.UseHangfireDashboard("hangfire", new DashboardOptions
設定 UI 為 ReadOnly 設定 UI 為 ReadOnly
``` ```C#
app.UseHangfireDashboard("hangfire", new DashboardOptions app.UseHangfireDashboard("hangfire", new DashboardOptions
{ {
IsReadOnlyFunc = (DashboardContext context) => true, IsReadOnlyFunc = (DashboardContext context) => true,
@@ -118,7 +118,7 @@ app.UseHangfireDashboard("hangfire", new DashboardOptions
修改 Dashboard UI 的預設根路由 修改 Dashboard UI 的預設根路由
``` ```C#
app.UseHangfireDashboard("hangfire"); app.UseHangfireDashboard("hangfire");
``` ```
@@ -126,7 +126,7 @@ app.UseHangfireDashboard("hangfire");
修改返回按鈕的路由 修改返回按鈕的路由
``` ```C#
app.UseHangfireDashboard("hangfire", new DashboardOptions app.UseHangfireDashboard("hangfire", new DashboardOptions
{ {
AppPath = "/swagger", // 導向到 Swagger UI AppPath = "/swagger", // 導向到 Swagger UI
@@ -139,7 +139,7 @@ app.UseHangfireDashboard("hangfire", new DashboardOptions
設定不同資料來源的 Dashboard 設定不同資料來源的 Dashboard
``` ```C#
app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"), new DashboardOptions app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"), new DashboardOptions
{ {
Authorization = [new DashboardAuthorizationFilter()], Authorization = [new DashboardAuthorizationFilter()],
@@ -156,13 +156,13 @@ app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"), new Da
* Fire-and-Forget jobs: 將任務丟入執行佇列,直接執行 * Fire-and-Forget jobs: 將任務丟入執行佇列,直接執行
``` ```C#
BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-Forget")); BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-Forget"));
``` ```
* Delayed jobs: 延遲指定時間後,將任務丟入執行佇列 * Delayed jobs: 延遲指定時間後,將任務丟入執行佇列
``` ```C#
BackgroundJob.Schedule(() => Console.WriteLine("Delayed"), TimeSpan.FromDays(1)); BackgroundJob.Schedule(() => Console.WriteLine("Delayed"), TimeSpan.FromDays(1));
``` ```
@@ -239,7 +239,7 @@ Cron Expression [測試](https://crontab.guru/)
</tbody> </tbody>
</table> </table>
``` ```C#
RecurringJob.AddOrUpdate("job_id", () => Console.Write("Recurring By CRON"), Cron.Daily); RecurringJob.AddOrUpdate("job_id", () => Console.Write("Recurring By CRON"), Cron.Daily);
RecurringJob.AddOrUpdate("job_id", () => Console.Write("Recurring By CRON expressions"), "* 0/1 * * ? *"); 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"); RecurringJob.RemoveIfExists("job_id");
``` ```
手動觸發已存在的排程任務 手動觸發已存在的排程任務
``` ```C#
RecurringJob.Trigger("job_id"); RecurringJob.Trigger("job_id");
``` ```
* Continuations: 指定的任務完成後,才丟入執行佇列 * Continuations: 指定的任務完成後,才丟入執行佇列
``` ```C#
var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-Forget")); var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-Forget"));
BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations")); BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations"));
@@ -272,7 +272,7 @@ BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations"));
使用 IPerformContextAccessor 從 Hangfire 的 PerformContext 取得進度管理的元件後,透過 Console 提供的擴充輸出到 GUI 管理介面。 使用 IPerformContextAccessor 從 Hangfire 的 PerformContext 取得進度管理的元件後,透過 Console 提供的擴充輸出到 GUI 管理介面。
``` ```shell
NUGET INSTALL Bonura.Hangfire.PerformContextAccessor -Version 1.3.3 NUGET INSTALL Bonura.Hangfire.PerformContextAccessor -Version 1.3.3
NUGET INSTALL Hangfire.Console -Version 1.4.3 NUGET INSTALL Hangfire.Console -Version 1.4.3
@@ -282,7 +282,7 @@ NUGET INSTALL Hangfire.Console -Version 1.4.3
Console 套件同時也提供格式化輸出字串的功能。 Console 套件同時也提供格式化輸出字串的功能。
``` ```C#
// 取得 Hangfire 的進程管理 // 取得 Hangfire 的進程管理
var bar = context.WriteProgressBar(); var bar = context.WriteProgressBar();