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 Type | When It Runs | Common Use Cases |
|---|---|---|
| Queue Trigger | When a new message arrives in an Azure Storage Queue | Processing work items, handling asynchronous tasks |
| Timer Trigger | On a schedule defined by a CRON expression | Scheduled maintenance, periodic data synchronization |
| Blob Trigger | When a file is uploaded to an Azure Blob Storage container | Processing uploaded files, document conversion |
| Continuous | Runs continuously after the application starts | Long-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
- Open Workflow Studio.
- Right-click the package folder where you want to create the WebJob.
- Click New Extension or Library > Azure Services .Net 6.0.
- Open the properties window for the extension.
- Select the ServiceType property and choose your WebJob type:
AzWebJob_QueueTriggerAzWebJob_TimerTriggerAzWebJob_BlobTriggerAzWebJob_Continuous
- Save the WebJob.
- 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):
- In Visual Studio, click Build > Build Solution.
- The build process creates a deployment package in the
..\\EmpowerID\\WFS\\_microservicesfolder. - Locate the zip file named after your WebJob.
Deploy to Azure
WebJobs are deployed to Azure via the Portal:
- Open the Azure Portal and navigate to your App Service.
- If your WebJob requires application settings (Queue or Blob triggers), configure them first:
- Click Configuration in the left menu
- Click the Application settings tab
- Add required settings (see trigger-specific sections below)
- Click Save
- Click WebJobs in the left menu.
- Click the Add button.
- Enter the WebJob details:
- Name - Identifier for the WebJob
- File Upload - Select the zip file from the
_microservicesfolder - Type - Select Triggered (for Queue, Timer, Blob) or Continuous
- 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
- Navigate to your Azure Storage Queue in the Portal.
- Click Add message and enter text.
- Click OK.
- In your App Service WebJobs, click Run if needed.
- 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 minutes0 */1 * * * *- Every minute0 0 * * * *- Every hour0 0 0 * * *- Daily at midnight
Test
- After deployment, the WebJob appears in your App Service.
- Click Run to manually trigger the job.
- View logs to verify execution.
- 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
- Navigate to your Blob Storage container in the Portal.
- Click Upload and select a file.
- In your App Service WebJobs, click Run if needed.
- 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
- The WebJob starts automatically after deployment.
- Verify the WebJob shows a Running status in the Portal.
- 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
- Click the WebJob name in the WebJobs list.
- View execution history and status.
- Click individual runs to view detailed logs.
Updating Configuration
To update application settings after deployment:
- Navigate to your App Service in the Azure Portal.
- Click Configuration in the left menu.
- Update settings under Application settings.
- Click Save.
- Restart the WebJob if necessary.