Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article explains how to deploy WebJobs by using the Azure portal to upload an executable or script. WebJobs is a feature of Azure App Service 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.
Overview
WebJobs is a feature of Azure App Service 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.
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.
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.
WebJob types
Supported file types for scripts or programs
The following file types are supported:
- Using Windows cmd: .cmd, .bat, .exe
- Using PowerShell: .ps1
- Using Bash: .sh
- Using Node.js: .js
- Using Java: .jar
The necessary runtimes to run these file types are already installed on the web app instance.
Continuous vs. triggered WebJobs
The following table describes the differences between continuous and triggered WebJobs:
Continuous | Triggered |
---|---|
Starts immediately when the WebJob is created. To keep the job from ending, the program or script typically does its work inside an endless loop. If the job does end, you can restart it. Typically used with WebJobs SDK. | Starts only when triggered manually or on a schedule. |
Runs on all instances that the web app runs on. You can optionally restrict the WebJob to a single instance. | Runs on a single instance that Azure selects for load balancing. |
Supports remote debugging. | Doesn't support remote debugging. |
Code is deployed under \site\wwwroot\app_data\Jobs\Continuous . |
Code is deployed under \site\wwwroot\app_data\Jobs\Triggered . |
Note
A web app can time out after 20 minutes of inactivity, and only requests to the actual web app can reset the timer. Viewing the app's configuration in the Azure portal or making requests to the advanced tools site doesn't reset the timer. If you set the web app that hosts your job to run continuously, run on a schedule, or use event-driven triggers, enable the Always on setting on your web app's Azure Configuration pane. The Always on setting helps make sure that these kinds of WebJobs run reliably. This feature is available only in the Basic, Standard, and Premium pricing tiers.
Create a continuous WebJob
Important
When you have source control configured for your application, Webjobs should be deployed as part of the source control integration. After source control is configured for your application, a WebJob can't be added from the Azure portal.
In the Azure portal, go to the App Service page of your App Service web app, API app, or mobile app.
Under Settings in the left pane, select WebJobs, then select Add.
Fill in the Add WebJob settings as specified in the table, then select Create Webjob.
Setting Sample value Description Name myContinuousWebJob A unique WebJob name. Must start with a letter or a number and must not contain special characters other than "-"
and"_"
.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 section. Type Continuous The WebJob types are described earlier in this article. 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. 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.
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.
Create a manually triggered WebJob
In the Azure portal, go to the App Service page of your App Service web app, API app, or mobile app.
Under Settings in the left pane, select WebJobs, then select Add.
Fill in the Add WebJob settings as specified in the table, then select Create Webjob.
Setting Sample value Description Name myTriggeredWebJob A unique WebJob name. Must start with a letter or a number and must not contain special characters other than "-"
and"_"
.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 section. Type Triggered The WebJob types are described previously in this article. Triggers Manual 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.
To run a manually triggered WebJob, right-click the WebJob in the list and select the Run button, then confirm your selection.
Create a scheduled WebJob
A scheduled Webjob is also triggered. You can schedule the trigger to occur automatically on the schedule you specify.
In the Azure portal, go to the App Service page of your App Service web app, API app, or mobile app.
Under Settings in the left pane, select WebJobs, then select Add.
Fill in the Add WebJob settings as specified in the table, then select Create Webjob.
Setting Sample value Description Name myScheduledWebJob A unique WebJob name. Must start with a letter or a number and must not contain special characters other than "-"
and"_"
.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 section. Type Triggered The WebJob types are described earlier in this article. 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. CRON Expression 0 0/20 * * * * CRON expressions are described in the following section. 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.
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.
NCRONTAB expressions
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 in the portal or include a settings.job
file at the root of your WebJob .zip file, as in the following example:
{
"schedule": "0 */15 * * * *"
}
To learn more, see Scheduling a triggered WebJob.
Note
The default time zone used to run CRON expressions is Coordinated Universal Time (UTC). To have your CRON expression run based on another time zone, create an app setting for your function app named WEBSITE_TIME_ZONE. To learn more, see NCRONTAB time zones.
Manage WebJobs
You can manage the run state of individual WebJobs running in your site by using the Azure portal. 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.
You can also configure an app setting 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.
View the job history
For the WebJob you want to see, select Logs.
In the WebJob Details page, select a time to see details for one run.
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.
WebJob status
The following is a list of common WebJob states:
- Initializing: The app has started and the WebJob is going through its initialization process.
- Starting: The WebJob is starting up.
- Running: The WebJob is running.
- 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.
- 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.
- Aborted: This can occur for many of reasons, such as when a long-running WebJob reaches the time-out marker.