Loading...
Area: Episerver Customer-Centric DXP

WebJobs in DXP environments

Recommendations [hide]

What are WebJobs?

A WebJob is a feature of Azure App Service that lets you run arbitrary programs or scripts using the same App Service Plan resources as a web app. You can run any script or console application with WebJobs that you can run on a Windows computer, with some functional limitations.

To run a WebJob, you need an existing Azure App Service web app. You can run multiple WebJobs in a single App Service plan.

Note: In DXP environments, the deployment flow only supports the Continous WebJob type.

A continuous WebJob starts when you deploy it and continues to run in an endless loop. For example, you can use this kind of WebJob to poll a message for new items and process their contents. Because the WebJob is continuous, your process can start quickly after the message appears.

Create a WebJob project using Visual Studio

To create a WebJob that is deployed alongside an App Service web app, use the WebJobs project template. Add this template to an existing web app project by clicking the name of the web app project. Click Add and then click New Azure WebJob Project.

imageko6u.png

A dialog box appears to choose options to create new WebJob.

imagecmit4.png

The created project is a console application; it includes a Program.cs file, which contains a Main() method that is entry point for the application. In the Main() method, the application initiates and configures a JobHost object, which is the object that communicates with Azure when the WebJob is deployed. You can place connection strings in App.config and implement the logic that is executed in Functions.cs file.

The project template also creates a webjobs-list.json file in the Web App project:

{
  "$schema" : "http://schemastore.org/schemas/json/webjobs-list.json",
  "WebJobs" : [
               {
                 "filePath" : "../WebJobExample/WebJobExample.csproj"
               }
              ]
}

The filePath points to the WebJob project where it also has an auto-generated JSON file called webjob-publish-settings.json.

{
  "$schema"    : "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName" : "WebJobExample",
  "runMode"    : "Continuous"
}

In the file, runMode is specified as Continuous.

After deploying the site to the DXP environment, the WebJob is located at wwwroot\app_data\jobs\continuous. 

Note: An incorrect path causes the job to not work as expected.

imageofa7.png

Related topic

Do you find this information helpful? Please log in to provide feedback.

Last updated: Sep 04, 2020

Recommendations [hide]