|
| 1 | +--- |
| 2 | +title: How WebJobs run in Azure App Service |
| 3 | +description: Understand how WebJobs are discovered, triggered, and managed by the Kudu engine in Azure App Service. |
| 4 | +ms.topic: conceptual |
| 5 | +ms.service: app-service |
| 6 | +author: msangapu-msft |
| 7 | +ms.author: msangapu |
| 8 | +ms.date: 05/01/2025 |
| 9 | +--- |
| 10 | + |
| 11 | +# How WebJobs run in Azure App Service |
| 12 | + |
| 13 | +Azure WebJobs allow you to run background tasks within your App Service app, without needing separate infrastructure. These tasks are discovered and managed by the **Kudu engine**, which handles execution, monitoring, and log collection. |
| 14 | + |
| 15 | +This article explains how WebJobs are discovered, how the runtime decides what to execute, and how you can configure behavior using the optional `settings.job` file. |
| 16 | + |
| 17 | +## Job discovery and folder structure |
| 18 | + |
| 19 | +WebJobs are stored in the `site/wwwroot/App_Data/jobs/` folder of your App Service app. There are two subfolders: |
| 20 | + |
| 21 | +- `continuous/`: For long-running jobs that start automatically and run continuously. |
| 22 | +- `triggered/`: For jobs that run on-demand or on a schedule. |
| 23 | + |
| 24 | +Each job has its own subfolder under the corresponding type, named after the WebJob. For example: |
| 25 | + |
| 26 | +``` |
| 27 | +App_Data/jobs/triggered/myjob/ |
| 28 | +App_Data/jobs/continuous/myjob/ |
| 29 | +``` |
| 30 | + |
| 31 | +Inside the job folder, the Kudu engine looks for a file to execute. This file can be a script or executable. |
| 32 | + |
| 33 | +## Entry point detection |
| 34 | + |
| 35 | +The WebJob runtime executes the **first valid script or binary** it finds based on this order: |
| 36 | + |
| 37 | +1. `run.cmd` |
| 38 | +2. `run.bat` |
| 39 | +3. `run.exe` |
| 40 | +4. `run.ps1` |
| 41 | +5. `run.sh` |
| 42 | +6. `run.py` |
| 43 | +7. `run.php` |
| 44 | +8. `run.js` |
| 45 | +9. `run.fsx` |
| 46 | + |
| 47 | +> [NOTE] The file must be named exactly `run.*` — not `start.sh` or `job.py`. |
| 48 | +
|
| 49 | +The platform uses a run.* file (such as run.sh, run.py, or run.js) as the entry point for a WebJob. If no recognized run.* file is present, it may attempt to execute the first supported script file it finds in the archive. This fallback behavior can be unpredictable—especially when multiple script files are included—so it's strongly recommended to explicitly define a run.* file to ensure reliable execution. On Linux, `.sh` scripts must have a shebang (`#!`) and executable permissions. |
| 50 | + |
| 51 | +## WebJob configuration with settings.job |
| 52 | + |
| 53 | +You can customize WebJob behavior using an optional `settings.job` file (JSON format) placed in the job's root folder. This file supports several properties: |
| 54 | + |
| 55 | +| Property | Description | |
| 56 | +|----------|-------------| |
| 57 | +| `is_singleton` | (bool) Ensures only one instance of the job runs across all scaled-out instances. Default: `true`. | |
| 58 | +| `stopping_wait_time` | (number, seconds) Grace period before the job is killed on shutdown. | |
| 59 | +| `shutdownGraceTimeLimit` | (number, seconds) Max time given for shutdown before process is forcefully terminated. | |
| 60 | +| `run_mode` | (string) Values: `continuous`, `scheduled`, `on_demand`. Overrides job type detection. | |
| 61 | + |
| 62 | +### Example |
| 63 | +```json |
| 64 | +{ |
| 65 | + "is_singleton": true, |
| 66 | + "stopping_wait_time": 10, |
| 67 | + "shutdownGraceTimeLimit": 20, |
| 68 | + "run_mode": "scheduled" |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## Logging and diagnostics |
| 73 | + |
| 74 | +WebJob logs are handled by the Kudu engine and are available under the `App_Data/jobs/<type>/<jobname>` folder. Additionally, logs can be viewed in the Azure portal or accessed via the SCM (Kudu) endpoint: |
| 75 | + |
| 76 | +``` |
| 77 | +https://<your-app>.scm.azurewebsites.net/api/triggeredwebjobs/<job>/history |
| 78 | +``` |
| 79 | + |
| 80 | +Triggered WebJobs include a full history of executions. Continuous WebJobs stream logs in real time. |
| 81 | + |
| 82 | +## Platform-specific notes |
| 83 | + |
| 84 | +[!INCLUDE [webjob-types](./includes/webjobs-create/quickstart-php-windows-pivot.md)] |
| 85 | + |
| 86 | +## Troubleshooting tips |
| 87 | + |
| 88 | +- **WebJob not starting:** Check for a missing or misnamed `run.*` file. |
| 89 | +- **Permissions error (Linux):** Ensure the script has execute permissions. |
| 90 | +- **Job not stopping gracefully:** Use `settings.job` to define shutdown grace period. |
| 91 | + |
| 92 | +## See also |
| 93 | + |
| 94 | +- [WebJobs overview](./overview.md) |
| 95 | +- [Create a scheduled WebJob](./scheduled-webjob-quickstart.md) |
| 96 | +- [Kudu WebJobs wiki (GitHub)](https://github.com/projectkudu/kudu/wiki/WebJobs) |
| 97 | + |
0 commit comments