Azure Container App Jobs
Azure Container Apps jobs let you run containerized tasks that execute for a finite duration and exit. Unlike continuously-running Container Apps, jobs are purpose-built for batch processing, scheduled tasks, and event-driven workloads. The Aspire Azure Container App Jobs hosting integration exposes PublishAsAzureContainerAppJobpublishAsAzureContainerAppJobPublishAsAzureContainerAppJob and PublishAsScheduledAzureContainerAppJobpublishAsScheduledAzureContainerAppJobPublishAsScheduledAzureContainerAppJob extension methods so you can declare any ContainerResource or ExecutableResource, including a DotnetProjectResource, as an Azure Container App Job directly from your AppHost.
Supported resource types
Section titled “Supported resource types”The following resource types can be published as Azure Container App Jobs:
| Resource type | Description |
|---|---|
DotnetProjectResource | A .NET project or C# file-based app added via AddDotnetProjectaddDotnetProjectAddDotnetProject. |
ContainerResource | A container image added via AddContaineraddContainerAddContainer. |
ExecutableResource | An executable process added via AddExecutableaddExecutableAddExecutable. |
Publish a project as a Container App Job
Section titled “Publish a project as a Container App Job”Use PublishAsAzureContainerAppJob to deploy a project, container, or executable as an Azure Container App Job. Use PublishAsScheduledAzureContainerAppJob as a convenience wrapper that sets the cron schedule in one call.
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const dataProcessor = await builder.addDotnetProject("data-processor", "../DataProcessor/DataProcessor.csproj");await dataProcessor.publishAsScheduledAzureContainerAppJob("0 0 * * *"); // Every day at midnightvar builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("data-processor", "../DataProcessor/DataProcessor.csproj") .PublishAsScheduledAzureContainerAppJob("0 0 * * *"); // Every day at midnightpackage main
import ( "log"
"apphost/modules/aspire")
func main() { builder, err := aspire.CreateBuilder() if err != nil { log.Fatal(aspire.FormatError(err)) }
dataProcessor := builder.AddDotnetProject("data-processor", "../DataProcessor/DataProcessor.csproj") dataProcessor.PublishAsScheduledAzureContainerAppJob("0 0 * * *") // Every day at midnight
app, err := builder.Build() if err != nil { log.Fatal(aspire.FormatError(err)) } if err := app.Run(); err != nil { log.Fatal(aspire.FormatError(err)) }}Job trigger types
Section titled “Job trigger types”Azure Container App Jobs support three trigger types: manual, schedule, and event.
Manual trigger
Section titled “Manual trigger”var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("manual-task", "../ManualTask/ManualTask.csproj") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Manual; });Schedule trigger
Section titled “Schedule trigger”var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("scheduled-task", "../ScheduledTask/ScheduledTask.csproj") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Schedule; job.Configuration.ScheduleTriggerConfig.CronExpression = "0 */6 * * *"; // Every 6 hours job.Configuration.ScheduleTriggerConfig.Parallelism = 1; job.Configuration.ScheduleTriggerConfig.ReplicaCompletionCount = 1; });Event trigger
Section titled “Event trigger”var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("event-task", "../EventDrivenTask/EventDrivenTask.csproj") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Event; job.Configuration.EventTriggerConfig.Scale.MinExecutions = 1; job.Configuration.EventTriggerConfig.Scale.MaxExecutions = 10; job.Configuration.EventTriggerConfig.Parallelism = 1; job.Configuration.EventTriggerConfig.ReplicaCompletionCount = 1; });Advanced configuration
Section titled “Advanced configuration”Set resource requirements
Section titled “Set resource requirements”Configure CPU and memory for your job:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("intensive-task", "../ResourceIntensiveTask/ResourceIntensiveTask.csproj") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Manual; job.Template.Containers[0].Value!.Resources.Cpu = 1.0; job.Template.Containers[0].Value!.Resources.Memory = "2Gi"; });Add environment variables
Section titled “Add environment variables”Pass environment variables — including provisioning parameters — into the job container:
var builder = DistributedApplication.CreateBuilder(args);
var connectionString = builder.AddParameter("connectionString");
builder.AddDotnetProject("db-task", "../DatabaseTask/DatabaseTask.csproj") .PublishAsAzureContainerAppJob((infra, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Manual; job.Template.Containers[0].Value!.Env.Add(new ContainerAppEnvironmentVariable { Name = "ConnectionString", Value = connectionString.AsProvisioningParameter(infra) }); });Configure timeout and retry policy
Section titled “Configure timeout and retry policy”var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("retryable-task", "../RetryableTask/RetryableTask.csproj") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Manual; job.Configuration.ReplicaTimeout = 1800; // 30 minutes job.Configuration.ReplicaRetryLimit = 3; });Publish a container resource as a job
Section titled “Publish a container resource as a job”var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("batch-processor", "myregistry.azurecr.io/batch-processor:latest") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Schedule; job.Configuration.ScheduleTriggerConfig.CronExpression = "0 2 * * 0"; // Weekly on Sunday at 2 AM });Publish an executable resource as a job
Section titled “Publish an executable resource as a job”var builder = DistributedApplication.CreateBuilder(args);
builder.AddExecutable("data-script", "python", ".", "process_data.py") .PublishAsAzureContainerAppJob((_, job) => { job.Configuration.TriggerType = ContainerAppJobTriggerType.Manual; });See also
Section titled “See also”- Azure Container Apps jobs overview — Microsoft Learn reference for the underlying Azure resource.
- Configure Azure Container Apps — Customize Container Apps environments and resources in your AppHost.
- Azure integrations overview — Overview of all Aspire Azure hosting integrations.