Add ACA Container App Jobs extension methods for Event Triggers
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
ACA Container App Jobs supports a few different "event" trigger types:
* azure-servicebus
* azure-queue
* redis
* etc
According to https://docs.azure.cn/en-us/container-apps/jobs?tabs=azure-cli#event-driven-jobs and https://docs.azure.cn/en-us/container-apps/scale-app?pivots=azure-cli#custom, it supports any [ScaledJob](https://keda.sh/docs/latest/concepts/scaling-jobs/)-based KEDA scalers.
We should create helper methods for configuring these event triggers. Here's some example code for creating a storage queue event trigger:
```csharp
var storageQueue = builder.AddAzureStorage("storage")
.AddQueue("myqueue");
var processor = builder.AddProject("processor")
.WithReference(storageQueue).WaitFor(storageQueue);
processor
.PublishAsAzureContainerAppJob((infra, job) =>
{
var accountNameParameter = storageQueue.Resource.Parent.Parent.NameOutputReference.AsProvisioningParameter(infra);
if (!processor.Resource.TryGetLastAnnotation(out var identityAnnotation))
{
throw new InvalidOperationException("Identity annotation not found.");
}
job.Configuration.TriggerType = ContainerAppJobTriggerType.Event;
job.Configuration.EventTriggerConfig.Scale.Rules.Add(new ContainerAppJobScaleRule
{
Name = "queue-rule",
JobScaleRuleType = "azure-queue",
Metadata = new ObjectExpression(
new PropertyExpression("accountName", new IdentifierExpression(accountNameParameter.BicepIdentifier)),
new PropertyExpression("queueName", new StringLiteralExpression(storageQueue.Resource.QueueName)),
new PropertyExpression("queueLength", new IntLiteralExpression(1))
),
Identity = identityAnnotation.IdentityResource.Id.AsProvisioningParameter(infra)
});
});
```
Contributor guide
Assessment
This issue has not been assessed yet.