Skip to content

Commit b8ff3ee

Browse files
Merge pull request #298463 from cdpark/refresh-appservice-batch1
User Story 419632: Q&M: Freshness - Azure App Service - Apr - batch 1
2 parents f8e9008 + eca7ce1 commit b8ff3ee

File tree

3 files changed

+71
-52
lines changed

3 files changed

+71
-52
lines changed
-6.45 KB
Loading
Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Run background tasks with WebJobs
2+
title: Run Background Tasks with WebJobs
33
description: Learn how to use WebJobs to run background tasks in Azure App Service. Choose from various script formats and run them with CRON expressions.
44

55
ms.assetid: af01771e-54eb-4aea-af5f-f883ff39572b
6-
ms.topic: conceptual
7-
ms.date: 3/01/2024
6+
ms.topic: concept-article
7+
ms.date: 4/17/2025
88
author: msangapu-msft
99
ms.author: msangapu
1010
ms.reviewer: cephalin;suwatch;pbatum;naren.soni;
@@ -17,47 +17,66 @@ adobe-target-content: ./webjobs-create-ieux
1717

1818
# Run background tasks with WebJobs in Azure App Service
1919

20-
Deploy WebJobs by using the [Azure portal](https://portal.azure.com) to upload an executable or script. You can run background tasks in the Azure App Service.
21-
22-
If instead of the Azure App Service, you're using Visual Studio to develop and deploy WebJobs, see [Deploy WebJobs using Visual Studio](webjobs-dotnet-deploy-vs.md).
20+
This article explains how to deploy WebJobs by using the [Azure portal](https://portal.azure.com) to upload an executable or script. WebJobs is a feature of [Azure App Service](index.yml) that allows you to run a program or script in the same instance as a web app. All app service plans support WebJobs. There's no extra cost to use WebJobs.
2321

2422
> [!NOTE]
25-
> WebJobs for **Windows container**, **Linux code**, and **Linux container** is in preview. WebJobs for Windows code is generally available and not in preview.
26-
27-
## Overview
28-
29-
WebJobs is a feature of [Azure App Service](index.yml) that enables you to run a program or script in the same instance as a web app. All app service plans support WebJobs. There's no extra cost to use WebJobs.
23+
> WebJobs for *Windows container*, *Linux code*, and *Linux container* is in preview. WebJobs for Windows code is generally available and not in preview.
3024
31-
You can use the Azure WebJobs SDK with WebJobs to simplify many programming tasks. For more information, see [What is the WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk/wiki).
25+
If you're using Visual Studio instead of the Azure App Service to develop and deploy WebJobs, see [Develop and deploy WebJobs using Visual Studio](webjobs-dotnet-deploy-vs.md).
3226

33-
Azure Functions provides another way to run programs and scripts. For a comparison between WebJobs and Functions, see [Choose between Flow, Logic Apps, Functions, and WebJobs](../azure-functions/functions-compare-logic-apps-ms-flow-webjobs.md).
27+
Azure Functions provides another way to run programs and scripts. For a comparison between WebJobs and Functions, see [Choose the right integration and automation services in Azure](../azure-functions/functions-compare-logic-apps-ms-flow-webjobs.md).
3428

3529
## WebJob types
3630

3731
### <a name="acceptablefiles"></a>Supported file types for scripts or programs
3832

3933
### [Windows code](#tab/windowscode)
40-
The following file types are supported:<br>
41-
**.cmd**, **.bat**, **.exe** (using Windows cmd)<br>**.ps1** (using PowerShell)<br>**.sh** (using Bash)<br>**.js** (using Node.js)<br>**.jar** (using Java)<br><br>The necessary runtimes to run these file types are already installed on the web app instance.
34+
35+
The following file types are supported:
36+
37+
- Using Windows cmd: *.cmd*, *.bat*, *.exe*
38+
- Using PowerShell: *.ps1*
39+
- Using Bash: *.sh*
40+
- Using Node.js: *.js*
41+
- Using Java: *.jar*
42+
43+
The necessary runtimes to run these file types are already installed on the web app instance.
44+
4245
### [Windows container](#tab/windowscontainer)
46+
4347
> [!NOTE]
4448
> WebJobs for Windows container is in preview.
4549
>
4650
47-
The following file types are supported:<br>
48-
**.cmd**, **.bat**, **.exe** (using Windows cmd)<br><br>In addition to these file types, WebJobs written in the language runtime of the Windows container app.<br>Example: .jar and .war scripts if the container is a Java app.
51+
The following file types are supported using Windows cmd: *.cmd*, *.bat*, *.exe*
52+
53+
In addition to these file types, WebJobs written in the language runtime of the Windows container app are supported.
54+
55+
- Example: *.jar* and *.war* scripts are supported if the container is a Java app.
56+
4957
### [Linux code](#tab/linuxcode)
58+
5059
> [!NOTE]
5160
> WebJobs for Linux code is in preview.
5261
>
5362
54-
**.sh** scripts are supported.<br><br>In addition to shell scripts, WebJobs written in the language of the selected runtime are also supported.<br>Example: Python (.py) scripts if the main site is a Python code app.
63+
*.sh* scripts are supported.
64+
65+
In addition to shell scripts, WebJobs written in the language of the selected runtime are also supported.
66+
67+
- Example: Python (*.py*) scripts are supported if the main site is a Python app.
68+
5569
### [Linux container](#tab/linuxcontainer)
70+
5671
> [!NOTE]
57-
> WebJobs for Linux container is in preview.
72+
> WebJobs for Linux container is in preview.
5873
>
5974
60-
**.sh** scripts are supported. <br><br>In addition to shell scripts, WebJobs written in the language runtime of the Linux container app are also supported. <br>Example: Node (.js) scripts if the site is a Node.js app.
75+
*.sh* scripts are supported.
76+
77+
In addition to shell scripts, WebJobs written in the language runtime of the Linux container app are also supported.
78+
79+
- Example: Node (*.js*) scripts are supported if the site is a Node.js app.
6180

6281
---
6382

@@ -88,17 +107,17 @@ when making changes in one don't forget the other two.
88107
89108
1. In the [Azure portal](https://portal.azure.com), go to the **App Service** page of your App Service web app, API app, or mobile app.
90109

91-
1. From the left pane, select **WebJobs**, then select **Add**.
110+
1. Under **Settings** in the left pane, select **WebJobs**, then select **Add**.
92111

93-
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal.":::
112+
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal." lightbox="media/webjobs-create/add-webjob.png":::
94113

95114
1. Fill in the **Add WebJob** settings as specified in the table, then select **Create Webjob**.
96115

97116
:::image type="content" source="media/webjobs-create/configure-new-continuous-webjob.png" alt-text="Screenshot that shows how to configure a multi-instance continuous WebJob for an App Service app.":::
98117

99118
| Setting | Sample value | Description  |
100119
| ------------ | ----------------- | ------------ |
101-
| **Name** | myContinuousWebJob | A name that is unique within an App Service app. Must start with a letter or a number and must not contain special characters other than "-" and "_". |
120+
| **Name** | myContinuousWebJob | A unique WebJob name. Must start with a letter or a number and must not contain special characters other than `"-"` and `"_"`. |
102121
| **File Upload** | ConsoleApp.zip | A *.zip* file that contains your executable or script file and any supporting files needed to run the program or script. The supported executable or script file types are listed in the [Supported file types](#acceptablefiles) section. |
103122
| **Type** | Continuous | The [WebJob types](#webjob-types) are described earlier in this article. |
104123
| **Scale** | Multi Instance | Available only for Continuous WebJobs. Determines whether the program or script runs on all instances or one instance. The option to run on multiple instances doesn't apply to the Free or Shared [pricing tiers](https://azure.microsoft.com/pricing/details/app-service/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). |
@@ -107,7 +126,7 @@ when making changes in one don't forget the other two.
107126

108127
1. To stop or restart a continuous WebJob, right-click the WebJob in the list and select the **Stop** or **Run** button, then confirm your selection.
109128

110-
:::image type="content" source="media/webjobs-create/continuous-webjob-stop.png" alt-text="Screenshot that shows how to stop a continuous WebJob in the Azure portal.":::
129+
:::image type="content" source="media/webjobs-create/continuous-webjob-stop.png" alt-text="Screenshot that shows how to stop a continuous WebJob in the Azure portal." lightbox="media/webjobs-create/continuous-webjob-stop.png":::
111130

112131
## <a name="CreateOnDemand"></a> Create a manually triggered WebJob
113132

@@ -118,17 +137,17 @@ when making changes in one don't forget the other two.
118137

119138
1. In the [Azure portal](https://portal.azure.com), go to the **App Service** page of your App Service web app, API app, or mobile app.
120139

121-
1. From the left pane, select **WebJobs**, then select **Add**.
140+
1. Under **Settings** in the left pane, select **WebJobs**, then select **Add**.
122141

123-
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal (manually triggered WebJob).":::
142+
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal (manually triggered WebJob)." lightbox="media/webjobs-create/add-webjob.png":::
124143

125144
1. Fill in the **Add WebJob** settings as specified in the table, then select **Create Webjob**.
126145

127146
:::image type="content" source="media/webjobs-create/configure-new-triggered-webjob.png" alt-text="Screenshot that shows how to configure a manually triggered WebJob for an App Service app.":::
128147

129148
| Setting | Sample value | Description  |
130149
| ------------ | ----------------- | ------------ |
131-
| **Name** | myTriggeredWebJob | A name that is unique within an App Service app. Must start with a letter or a number and must not contain special characters other than "-" and "_".|
150+
| **Name** | myTriggeredWebJob | A unique WebJob name. Must start with a letter or a number and must not contain special characters other than `"-"` and `"_"`. |
132151
| **File Upload** | ConsoleApp1.zip | A *.zip* file that contains your executable or script file and any supporting files needed to run the program or script. The supported executable or script file types are listed in the [Supported file types](#acceptablefiles) section. |
133152
| **Type** | Triggered | The [WebJob types](#webjob-types) are described previously in this article. |
134153
| **Triggers** | Manual | |
@@ -137,7 +156,7 @@ when making changes in one don't forget the other two.
137156

138157
1. To run a manually triggered WebJob, right-click the WebJob in the list and select the **Run** button, then confirm your selection.
139158

140-
:::image type="content" source="media/webjobs-create/triggered-webjob-run.png" alt-text="Screenshot that shows how to run a manually triggered WebJob in the Azure portal.":::
159+
:::image type="content" source="media/webjobs-create/triggered-webjob-run.png" alt-text="Screenshot that shows how to run a manually triggered WebJob in the Azure portal." lightbox="media/webjobs-create/triggered-webjob-run.png":::
141160

142161
## <a name="CreateScheduledCRON"></a> Create a scheduled WebJob
143162

@@ -150,31 +169,31 @@ when making changes in one don't forget the other two.
150169

151170
1. In the [Azure portal](https://portal.azure.com), go to the **App Service** page of your App Service web app, API app, or mobile app.
152171

153-
1. From the left pane, select **WebJobs**, then select **Add**.
172+
1. Under **Settings** in the left pane, select **WebJobs**, then select **Add**.
154173

155-
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal (scheduled WebJob).":::
174+
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal (scheduled WebJob)." lightbox="media/webjobs-create/add-webjob.png":::
156175

157176
1. Fill in the **Add WebJob** settings as specified in the table, then select **Create Webjob**.
158177

159178
:::image type="content" source="media/webjobs-create/configure-new-scheduled-webjob.png" alt-text="Screenshot that shows how to configure a scheduled WebJob in an App Service app.":::
160179

161180
| Setting | Sample value | Description  |
162181
| ------------ | ----------------- | ------------ |
163-
| **Name** | myScheduledWebJob | A name that is unique within an App Service app. Must start with a letter or a number and must not contain special characters other than "-" and "_". |
182+
| **Name** | myScheduledWebJob | A unique WebJob name. Must start with a letter or a number and must not contain special characters other than `"-"` and `"_"`. |
164183
| **File Upload** | ConsoleApp.zip | A *.zip* file that contains your executable or script file and any supporting files needed to run the program or script. The supported executable or script file types are listed in the [Supported file types](#acceptablefiles) section. |
165184
| **Type** | Triggered | The [WebJob types](#webjob-types) are described earlier in this article. |
166185
| **Triggers** | Scheduled | For the scheduling to work reliably, enable the Always On feature. Always On is available only in the Basic, Standard, and Premium pricing tiers.|
167186
| **CRON Expression** | 0 0/20 * * * * | [CRON expressions](#ncrontab-expressions) are described in the following section. |
168187

169188
1. The new WebJob appears on the **WebJobs** page. If you see a message that says the WebJob was added, but you don't see it, select **Refresh**.
170189

171-
1. The scheduled WebJob is run at the schedule defined by the CRON expression. To run it manually at anytime, right-click the WebJob in the list and select the **Run** button, then confirm your selection.
190+
1. The scheduled WebJob is run according to the schedule defined by the CRON expression. To run it manually at anytime, right-click the WebJob in the list and select the **Run** button, then confirm your selection.
172191

173-
:::image type="content" source="media/webjobs-create/scheduled-webjob-run.png" alt-text="Screenshot that shows how to run a manually scheduled WebJob in the Azure portal.":::
192+
:::image type="content" source="media/webjobs-create/scheduled-webjob-run.png" alt-text="Screenshot that shows how to run a manually scheduled WebJob in the Azure portal." lightbox="media/webjobs-create/scheduled-webjob-run.png":::
174193

175194
## NCRONTAB expressions
176195

177-
You can enter a [NCRONTAB expression](../azure-functions/functions-bindings-timer.md#ncrontab-expressions) in the portal or include a `settings.job` file at the root of your WebJob *.zip* file, as in the following example:
196+
An NCRONTAB expression is similar to a CRON expression, but includes an additional sixth field at the beginning for time precision in seconds. You can enter an [NCRONTAB expression](../azure-functions/functions-bindings-timer.md#ncrontab-expressions) in the portal or include a `settings.job` file at the root of your WebJob *.zip* file, as in the following example:
178197

179198
```json
180199
{
@@ -188,33 +207,33 @@ To learn more, see [Scheduling a triggered WebJob](webjobs-dotnet-deploy-vs.md#s
188207

189208
## Manage WebJobs
190209

191-
You can manage the running state individual WebJobs running in your site in the [Azure portal](https://portal.azure.com). Go to **Settings** > **WebJobs**, choose the WebJob, and you can start and stop the WebJob. You can also view and modify the password of the webhook that runs the WebJob.
210+
You can manage the run state of individual WebJobs running in your site by using the [Azure portal](https://portal.azure.com). Go to **Settings** > **WebJobs**, choose the WebJob, and you can start and stop the WebJob. You can also view and modify the password of the webhook that runs the WebJob.
192211

193-
You can also [add an application setting](configure-common.md#configure-app-settings) named `WEBJOBS_STOPPED` with a value of `1` to stop all WebJobs running on your site. You can use this method to prevent conflicting WebJobs from running both in staging and production slots. You can similarly use a value of `1` for the `WEBJOBS_DISABLE_SCHEDULE` setting to disable triggered WebJobs in the site or a staging slot. For slots, remember to enable the **Deployment slot setting** option so that the setting itself doesn't get swapped.
212+
You can also [configure an app setting](configure-common.md#configure-app-settings) named `WEBJOBS_STOPPED` with a value of `1` to stop all WebJobs running on your site. You can use this method to prevent conflicting WebJobs from running both in staging and production slots. You can similarly use a value of `1` for the `WEBJOBS_DISABLE_SCHEDULE` setting to disable triggered WebJobs in the site or a staging slot. For slots, remember to enable the **Deployment slot setting** option so that the setting itself doesn't get swapped.
194213

195214
## <a name="ViewJobHistory"></a> View the job history
196215

197216
1. For the WebJob you want to see, select **Logs**.
198217

199-
:::image type="content" source="media/webjobs-create/open-logs.png" alt-text="Screenshot that shows how to access logs for a WebJob.":::
200-
201-
2. In the **WebJob Details** page, select a time to see details for one run.
202-
203-
:::image type="content" source="media/webjobs-create/webjob-details-page.png" alt-text="Screenshot that shows how to choose a WebJob run to see its detailed logs.":::
218+
:::image type="content" source="media/webjobs-create/open-logs.png" alt-text="Screenshot that shows how to access logs for a WebJob." lightbox="media/webjobs-create/open-logs.png":::
219+
220+
1. In the **WebJob Details** page, select a time to see details for one run.
221+
222+
:::image type="content" source="media/webjobs-create/webjob-details-page.png" alt-text="Screenshot that shows how to choose a WebJob run to see its detailed logs." lightbox="media/webjobs-create/webjob-details-page.png":::
204223

205-
3. In the **WebJob Run Details** page, you can select **download** to get a text file of the logs, or select the **WebJobs** breadcrumb link at the top of the page to see logs for a different WebJob.
224+
1. In the **WebJob Run Details** page, you can select **download** to get a text file of the logs, or select the **WebJobs** breadcrumb link at the top of the page to see logs for a different WebJob.
206225

207-
## WebJob statuses
226+
## WebJob status
208227

209-
The following is a list of common WebJob statuses:
228+
The following is a list of common WebJob states:
210229

211-
- **Initializing** The app has started and the WebJob is going through its initialization process.
212-
- **Starting** The WebJob is starting up.
213-
- **Running** The WebJob is running.
214-
- **PendingRestart** A continuous WebJob exits in less than two minutes since it started for any reason, and App Service waits 60 seconds before restarting the WebJob. If the continuous WebJob exits after the two-minute mark, App Service doesn't wait the 60 seconds and restarts the WebJob immediately.
215-
- **Stopped** The WebJob was stopped (usually from the Azure portal) and is currently not running and won't run until you start it again manually, even for a continuous or scheduled WebJob.
216-
- **Aborted** This can occur for many of reasons, such as when a long-running WebJob reaches the timeout marker.
230+
- **Initializing**: The app has started and the WebJob is going through its initialization process.
231+
- **Starting**: The WebJob is starting up.
232+
- **Running**: The WebJob is running.
233+
- **PendingRestart**: A continuous WebJob exits in less than two minutes since it started for any reason, and App Service waits 60 seconds before restarting the WebJob. If the continuous WebJob exits after the two-minute mark, App Service doesn't wait the 60 seconds and restarts the WebJob immediately.
234+
- **Stopped**: The WebJob was stopped (usually from the Azure portal) and is currently not running and won't run until you start it again manually, even for a continuous or scheduled WebJob.
235+
- **Aborted**: This can occur for many of reasons, such as when a long-running WebJob reaches the time-out marker.
217236

218-
## <a name="NextSteps"></a> Next steps
237+
## <a name="NextSteps"></a> Next step
219238

220239
The Azure WebJobs SDK can be used with WebJobs to simplify many programming tasks. For more information, see [What is the WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk/wiki).

0 commit comments

Comments
 (0)