Skip to main content

Create Azure WebJobs

Azure WebJobs enable applications to run background tasks in the same instance as a web app. Workflow Studio provides templates for creating WebJobs with different trigger types that determine when the WebJob executes.

WebJob Trigger Types

Workflow Studio supports four WebJob templates:

Trigger TypeWhen It RunsCommon Use Cases
Queue TriggerWhen a new message arrives in an Azure Storage QueueProcessing work items, handling asynchronous tasks
Timer TriggerOn a schedule defined by a CRON expressionScheduled maintenance, periodic data synchronization
Blob TriggerWhen a file is uploaded to an Azure Blob Storage containerProcessing uploaded files, document conversion
ContinuousRuns continuously after the application startsLong-running background processes, monitoring tasks

Prerequisites

Before creating WebJobs, ensure you have:

  • Workflow Studio installed and configured
  • Visual Studio installed
  • An Azure subscription with an App Service created
  • Azure Storage account configured
  • For Queue Trigger: An Azure Storage Queue created
  • For Blob Trigger: An Azure Blob Storage container created

Create a WebJob Project

  1. Open Workflow Studio.
  2. Right-click the package folder where you want to create the WebJob.
  3. Click New Extension or Library > Azure Services .Net 6.0.
  4. Open the properties window for the extension.
  5. Select the ServiceType property and choose your WebJob type:
    • AzWebJob_QueueTrigger
    • AzWebJob_TimerTrigger
    • AzWebJob_BlobTrigger
    • AzWebJob_Continuous
  6. Save the WebJob.
  7. Double-click the WebJob in the Solution Explorer to open it in Visual Studio.

Build and Package

After implementing your WebJob logic (see trigger-specific sections below):

  1. In Visual Studio, click Build > Build Solution.
  2. The build process creates a deployment package in the ..\\EmpowerID\\WFS\\_microservices folder.
  3. Locate the zip file named after your WebJob.

Deploy to Azure

WebJobs are deployed to Azure via the Portal:

  1. Open the Azure Portal and navigate to your App Service.
  2. If your WebJob requires application settings (Queue or Blob triggers), configure them first:
    1. Click Configuration in the left menu
    2. Click the Application settings tab
    3. Add required settings (see trigger-specific sections below)
    4. Click Save
  3. Click WebJobs in the left menu.
  4. Click the Add button.
  5. Enter the WebJob details:
    • Name - Identifier for the WebJob
    • File Upload - Select the zip file from the _microservices folder
    • Type - Select Triggered (for Queue, Timer, Blob) or Continuous
  6. Click OK to save the WebJob.

Queue Trigger Configuration

Queue Trigger WebJobs execute when a message arrives in an Azure Storage Queue.

Configure in Visual Studio

Open the Appsettings.json file and update:

{
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=your-storage-account;AccountKey=your-key;EndpointSuffix=core.windows.net",
"QueueName": "your-queue-name"
}

Implement Logic

The generated MyWebJob.cs file contains:

public async Task ProcessQueueMessageAsync([QueueTrigger("%QueueName%")] string message, ILogger logger)
{
logger.LogInformation($"Processing queue message: {message}");
// Add your custom logic here
}

Configure in Azure

When deploying, add this application setting:

  • Setting name: QueueName
  • Value: Your queue name (must match Appsettings.json)

Test

  1. Navigate to your Azure Storage Queue in the Portal.
  2. Click Add message and enter text.
  3. Click OK.
  4. In your App Service WebJobs, click Run if needed.
  5. View logs to verify the message was processed.

Timer Trigger Configuration

Timer Trigger WebJobs execute on a schedule defined by a CRON expression.

Configure in Visual Studio

Open the Appsettings.json file and update:

{
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=your-storage-account;AccountKey=your-key;EndpointSuffix=core.windows.net"
}

Implement Logic

The generated MyWebJob.cs file contains:

public void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
// Add your custom logic here
}

CRON Expression Examples:

  • 0 */5 * * * * - Every 5 minutes
  • 0 */1 * * * * - Every minute
  • 0 0 * * * * - Every hour
  • 0 0 0 * * * - Daily at midnight

Test

  1. After deployment, the WebJob appears in your App Service.
  2. Click Run to manually trigger the job.
  3. View logs to verify execution.
  4. The job will automatically run based on the CRON schedule.

Blob Trigger Configuration

Blob Trigger WebJobs execute when a file is uploaded to an Azure Blob Storage container.

Configure in Visual Studio

Open the Appsettings.json file and update:

{
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=your-storage-account;AccountKey=your-key;EndpointSuffix=core.windows.net",
"BlobContainerName": "your-container-name"
}

Implement Logic

The generated MyWebJob.cs file contains:

public void BlobTrigger([BlobTrigger("%BlobContainerName%/{name}")] Stream myBlob, string name, ILogger log)
{
log.LogInformation($"Blob trigger function processed blob\n Name: {name} \n Size: {myBlob.Length} Bytes");
// Add your custom logic here
}

Configure in Azure

When deploying, add this application setting:

  • Setting name: BlobContainerName
  • Value: Your container name (must match Appsettings.json)

Test

  1. Navigate to your Blob Storage container in the Portal.
  2. Click Upload and select a file.
  3. In your App Service WebJobs, click Run if needed.
  4. View logs to verify the file was processed.

Continuous WebJob Configuration

Continuous WebJobs run continuously in the background after the application starts.

Configure in Visual Studio

Open the Appsettings.json file and update:

{
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=your-storage-account;AccountKey=your-key;EndpointSuffix=core.windows.net"
}

Implement Logic

The generated MyWebJob.cs file contains:

public async Task Run(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
_logger.LogInformation($"Continuous WebJob running at: {DateTime.Now}");

// Add your custom logic here

await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken);
}
}

Use the cancellationToken to handle graceful shutdown.

Test

  1. The WebJob starts automatically after deployment.
  2. Verify the WebJob shows a Running status in the Portal.
  3. View logs to confirm continuous execution.

Managing WebJobs in Azure

After deployment, manage WebJobs through the Azure Portal:

Starting and Stopping

  • Click Start to start a stopped WebJob
  • Click Stop to stop a running WebJob
  • Click Run to manually trigger a triggered WebJob

Viewing Logs

  1. Click the WebJob name in the WebJobs list.
  2. View execution history and status.
  3. Click individual runs to view detailed logs.

Updating Configuration

To update application settings after deployment:

  1. Navigate to your App Service in the Azure Portal.
  2. Click Configuration in the left menu.
  3. Update settings under Application settings.
  4. Click Save.
  5. Restart the WebJob if necessary.