Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;
using Azure.Provisioning.AppContainers;
using System.Diagnostics.CodeAnalysis;

namespace Aspire.Hosting;

Expand Down Expand Up @@ -48,4 +49,47 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu

return container;
}

/// <summary>
/// Publishes the specified container resource as an Azure Container App Job.
/// </summary>
/// <typeparam name="T">The type of the container resource.</typeparam>
/// <param name="container">The container resource builder.</param>
/// <param name="configure">The configuration action for the container app job.</param>
/// <returns>The updated container resource builder.</returns>
/// <remarks>
/// This method adds the necessary infrastructure for container app jobs to the application builder
/// and applies the specified configuration to the container app job.
///
/// Note that the default trigger type for the job is set to Manual, and the default replica timeout is set to 1800 seconds (30 minutes).
///
/// <example>
/// <code>
/// builder.AddContainer("name", "image").PublishAsAzureContainerAppJob((infrastructure, job) =>
/// {
/// // Configure the container app job here
/// job.Configuration.TriggerType = ContainerAppJobTriggerType.Schedule;
/// job.Configuration.ScheduleTriggerConfig.CronExpression = "0 0 * * *"; // every day at midnight
/// });
/// </code>
/// </example>
/// </remarks>
[Experimental("ASPIREAZURE002", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
public static IResourceBuilder<T> PublishAsAzureContainerAppJob<T>(this IResourceBuilder<T> container, Action<AzureResourceInfrastructure, ContainerAppJob> configure)
where T : ContainerResource
{
ArgumentNullException.ThrowIfNull(container);
ArgumentNullException.ThrowIfNull(configure);

if (!container.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
return container;
}

container.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();

container.WithAnnotation(new AzureContainerJobCustomizationAnnotation(configure));

return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;
using Azure.Provisioning.AppContainers;
using System.Diagnostics.CodeAnalysis;

namespace Aspire.Hosting;

Expand Down Expand Up @@ -48,4 +49,47 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu

return project;
}

/// <summary>
/// Allows configuring the specified project resource as an Azure Container App Job.
/// </summary>
/// <typeparam name="T">The type of the project resource.</typeparam>
/// <param name="project">The project resource builder.</param>
/// <param name="configure">The configuration action for the container app job.</param>
/// <returns>The updated project resource builder.</returns>
/// <remarks>
/// This method adds the necessary infrastructure for container app jobs to the application builder
/// and applies the specified configuration to the container app job.
///
/// Note that the default trigger type for the job is set to Manual, and the default replica timeout is set to 1800 seconds (30 minutes).
///
/// <example>
/// <code>
/// builder.AddProject&lt;Projects.Api&gt;.PublishAsAzureContainerAppJob((infrastructure, job) =>
/// {
/// // Configure the container app job here
/// job.Configuration.TriggerType = ContainerAppJobTriggerType.Schedule;
/// job.Configuration.ScheduleTriggerConfig.CronExpression = "0 0 * * *"; // every day at midnight
/// });
/// </code>
/// </example>
/// </remarks>
[Experimental("ASPIREAZURE002", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
public static IResourceBuilder<T> PublishAsAzureContainerAppJob<T>(this IResourceBuilder<T> project, Action<AzureResourceInfrastructure, ContainerAppJob> configure)
where T : ProjectResource
{
ArgumentNullException.ThrowIfNull(project);
ArgumentNullException.ThrowIfNull(configure);

if (!project.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
return project;
}

project.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();

project.WithAnnotation(new AzureContainerJobCustomizationAnnotation(configure));

return project;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
using Azure.Provisioning.AppContainers;

namespace Aspire.Hosting.Azure;

/// <summary>
/// Represents an annotation for customizing an Azure Container App Job.
/// </summary>
public sealed class AzureContainerJobCustomizationAnnotation(Action<AzureResourceInfrastructure, ContainerAppJob> configure)
: IResourceAnnotation
{
/// <summary>
/// Gets the configuration action for customizing the Azure Container Job.
/// </summary>
public Action<AzureResourceInfrastructure, ContainerAppJob> Configure { get; } = configure ?? throw new ArgumentNullException(nameof(configure));
}
Loading
Loading