From fd1d71ff058aba812617d921e9faff556d60a05a Mon Sep 17 00:00:00 2001 From: Esha Noronha Date: Fri, 27 Jun 2025 09:07:48 +0200 Subject: [PATCH 1/3] Formatted `IRecurringBackgroundJob` section for better readability --- 16/umbraco-cms/reference/scheduling.md | 73 +++++++++++++++----------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/16/umbraco-cms/reference/scheduling.md b/16/umbraco-cms/reference/scheduling.md index 5ef2ce78f9a..24f0099a05f 100644 --- a/16/umbraco-cms/reference/scheduling.md +++ b/16/umbraco-cms/reference/scheduling.md @@ -12,50 +12,61 @@ Once you have created your background job class, register it using a Composer. I Be aware you may or may not want this background job to run on all servers. If you are using Load Balancing with multiple servers, see [load balancing documentation](../fundamentals/setup/server-setup/load-balancing/) for more information {% endhint %} -## `IRecurringBackgroundJob` +## `IRecurringBackgroundJob` Properties and Methods -- `Period` - this property is a `TimeSpan` that tells Umbraco how often to run your job. +### `Period` - ```c# - // Run this job every 5 minutes - TimeSpan Period = TimeSpan.FromMinutes(5); - ``` +Defines how often the job runs. This property is a `TimeSpan`. -- `Delay` - this property is also a `TimeSpan` that tells Umbraco how long to wait after starting up before running the task for the first time. The default is 3 minutes. +```csharp +// Run this job every 5 minutes +TimeSpan Period = TimeSpan.FromMinutes(5); +``` - ```c# - // Wait 3 minutes after application startup before starting to run this job. - TimeSpan Delay = TimeSpan.FromMinutes(3); - ``` +### `Delay` -- `ServerRoles` - a list of roles that should run this job. In a multi-server setup, you may want your job to run on _all_ servers, or only on _one_ of your servers. - For example, a temporary file cleanup task might need to run on all servers. A database import job might be better to be run once per day on a single server. +Defines how long to wait after application startup before running the task for the first time. Default is 3 minutes. This property is a `TimeSpan`. - The default value is: `{ Single, SchedulingPublisher }`, which will cause the job to only run on _one_ server. +```csharp +// Wait 3 minutes after application startup before starting to run this job. +TimeSpan Delay = TimeSpan.FromMinutes(3); +``` - ```c# - // Run this job on ALL servers - ServerRole[] ServerRoles = Enum.GetValues(); - ``` +### `ServerRoles` - For more information about server roles, see the [Load Balancing](../fundamentals/setup/server-setup/load-balancing#scheduling-and-server-role-election) documentation. +Specifies a list of roles that should run this job. In a multi-server setup, you may want your job to run on _all_ servers or only on _one_ of your servers. -- `PeriodChanged` - an event you can trigger to tell the background job service that the period has changed. For example, if the period for your job is controlled by a configuration file setting. +For example, a temporary file cleanup task might need to run on all servers. A database import job might be better to be run once per day on a single server. - ```c# - // No-op event as the period never changes on this job - public event EventHandler PeriodChanged { add { } remove { } } - ``` +By default: `{ Single, SchedulingPublisher }`, meaning it runs on one server only. - See below for a full example of how to implement the PeriodChanged event. +```csharp +// Run this job on all servers +ServerRole[] ServerRoles = Enum.GetValues(); +``` -- `RunJobAsync()` - the main method of your job. +For more information about server roles, see the [Load Balancing](../fundamentals/setup/server-setup/load-balancing/README.md#scheduling-and-server-role-election) documentation. - ```c# - public Task RunJobAsync() { - // your job code goes here - } - ``` +### `PeriodChanged` + +An event used to notify the background job service if the job’s period changes dynamically. For example, if the period for your job is controlled by a configuration file setting, you can trigger the `PeriodChanged` event when the configuration changes. + +```csharp +// No-op event as the period never changes on this job +public event EventHandler PeriodChanged { add { } remove { } } +``` + +See [Minimal example](#minimal-example) on how to implement the `PeriodChanged` event. + +### `RunJobAsync()` + +The main method where your job logic is implemented. + +```csharp +public Task RunJobAsync() { +// your job code goes here +} +``` ## Minimal example From 368215a01e124d37fef5b3cec2828d484c357ba3 Mon Sep 17 00:00:00 2001 From: Esha Noronha Date: Fri, 27 Jun 2025 09:13:13 +0200 Subject: [PATCH 2/3] More formatting --- 16/umbraco-cms/reference/scheduling.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/16/umbraco-cms/reference/scheduling.md b/16/umbraco-cms/reference/scheduling.md index 24f0099a05f..dca2910fde6 100644 --- a/16/umbraco-cms/reference/scheduling.md +++ b/16/umbraco-cms/reference/scheduling.md @@ -49,14 +49,16 @@ For more information about server roles, see the [Load Balancing](../fundamental ### `PeriodChanged` -An event used to notify the background job service if the job’s period changes dynamically. For example, if the period for your job is controlled by a configuration file setting, you can trigger the `PeriodChanged` event when the configuration changes. +An event used to notify the background job service if the job’s period changes dynamically. + +For example, if the period for your job is controlled by a configuration file setting, you can trigger the `PeriodChanged` event when the configuration changes. ```csharp // No-op event as the period never changes on this job public event EventHandler PeriodChanged { add { } remove { } } ``` -See [Minimal example](#minimal-example) on how to implement the `PeriodChanged` event. +See the [Example](#example) below on how to implement the `PeriodChanged` event. ### `RunJobAsync()` @@ -68,7 +70,7 @@ public Task RunJobAsync() { } ``` -## Minimal example +## Example This example shows the minimum code necessary to implement the `IRecurringBackgroundJob` interface. The job runs every 60 minutes on all servers. From 7696a3e0d0eec288c46190099519da53099ca31b Mon Sep 17 00:00:00 2001 From: Esha Noronha Date: Fri, 27 Jun 2025 09:16:31 +0200 Subject: [PATCH 3/3] Removed formatting from headings --- 16/umbraco-cms/reference/scheduling.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/16/umbraco-cms/reference/scheduling.md b/16/umbraco-cms/reference/scheduling.md index dca2910fde6..97dc57e1de2 100644 --- a/16/umbraco-cms/reference/scheduling.md +++ b/16/umbraco-cms/reference/scheduling.md @@ -14,7 +14,7 @@ Be aware you may or may not want this background job to run on all servers. If y ## `IRecurringBackgroundJob` Properties and Methods -### `Period` +### Period Defines how often the job runs. This property is a `TimeSpan`. @@ -23,7 +23,7 @@ Defines how often the job runs. This property is a `TimeSpan`. TimeSpan Period = TimeSpan.FromMinutes(5); ``` -### `Delay` +### Delay Defines how long to wait after application startup before running the task for the first time. Default is 3 minutes. This property is a `TimeSpan`. @@ -32,7 +32,7 @@ Defines how long to wait after application startup before running the task for t TimeSpan Delay = TimeSpan.FromMinutes(3); ``` -### `ServerRoles` +### ServerRoles Specifies a list of roles that should run this job. In a multi-server setup, you may want your job to run on _all_ servers or only on _one_ of your servers. @@ -47,7 +47,7 @@ ServerRole[] ServerRoles = Enum.GetValues(); For more information about server roles, see the [Load Balancing](../fundamentals/setup/server-setup/load-balancing/README.md#scheduling-and-server-role-election) documentation. -### `PeriodChanged` +### PeriodChanged An event used to notify the background job service if the job’s period changes dynamically. @@ -60,7 +60,7 @@ public event EventHandler PeriodChanged { add { } remove { } } See the [Example](#example) below on how to implement the `PeriodChanged` event. -### `RunJobAsync()` +### RunJobAsync() The main method where your job logic is implemented.