Skip to content

Commit a666e97

Browse files
author
Jill Grant
authored
Merge pull request #267628 from anthonychu/20240227-aca-jobs-update
[Container Apps] Jobs updates
2 parents 33844df + a157b94 commit a666e97

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

articles/container-apps/jobs-get-started-cli.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To use manual jobs, you first create a job with trigger type `Manual` and then s
3333
az containerapp job create \
3434
--name "$JOB_NAME" --resource-group "$RESOURCE_GROUP" --environment "$ENVIRONMENT" \
3535
--trigger-type "Manual" \
36-
--replica-timeout 1800 --replica-retry-limit 1 --replica-completion-count 1 --parallelism 1 \
36+
--replica-timeout 1800 \
3737
--image "mcr.microsoft.com/k8se/quickstart-jobs:latest" \
3838
--cpu "0.25" --memory "0.5Gi"
3939
```
@@ -64,7 +64,7 @@ Create a job in the Container Apps environment that starts every minute using th
6464
az containerapp job create \
6565
--name "$JOB_NAME" --resource-group "$RESOURCE_GROUP" --environment "$ENVIRONMENT" \
6666
--trigger-type "Schedule" \
67-
--replica-timeout 1800 --replica-retry-limit 1 --replica-completion-count 1 --parallelism 1 \
67+
--replica-timeout 1800 \
6868
--image "mcr.microsoft.com/k8se/quickstart-jobs:latest" \
6969
--cpu "0.25" --memory "0.5Gi" \
7070
--cron-expression "*/1 * * * *"

articles/container-apps/jobs.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: craigshoemaker
66
ms.service: container-apps
77
ms.custom: build-2023, devx-track-azurecli
88
ms.topic: conceptual
9-
ms.date: 08/17/2023
9+
ms.date: 04/02/2024
1010
ms.author: cshoe
1111
---
1212

@@ -33,12 +33,22 @@ The following table compares common scenarios for apps and jobs:
3333
| An HTTP server that serves web content and API requests | App | Configure an [HTTP scale rule](scale-app.md#http). |
3434
| A process that generates financial reports nightly | Job | Use the [*Schedule* job type](#scheduled-jobs) and configure a cron expression. |
3535
| A continuously running service that processes messages from an Azure Service Bus queue | App | Configure a [custom scale rule](scale-app.md#custom). |
36-
| A job that processes a single message or a small batch of messages from an Azure queue and exits | Job | Use the *Event* job type and [configure a custom scale rule](tutorial-event-driven-jobs.md) to trigger job executions. |
36+
| A job that processes a single message or a small batch of messages from an Azure queue and exits | Job | Use the *Event* job type and [configure a custom scale rule](tutorial-event-driven-jobs.md) to trigger job executions when there are messages in the queue. |
3737
| A background task that's triggered on-demand and exits when finished | Job | Use the *Manual* job type and [start executions](#start-a-job-execution-on-demand) manually or programmatically using an API. |
3838
| A self-hosted GitHub Actions runner or Azure Pipelines agent | Job | Use the *Event* job type and configure a [GitHub Actions](tutorial-ci-cd-runners-jobs.md?pivots=container-apps-jobs-self-hosted-ci-cd-github-actions) or [Azure Pipelines](tutorial-ci-cd-runners-jobs.md?pivots=container-apps-jobs-self-hosted-ci-cd-azure-pipelines) scale rule. |
3939
| An Azure Functions app | App | [Deploy Azure Functions to Container Apps](../azure-functions/functions-container-apps-hosting.md). |
4040
| An event-driven app using the Azure WebJobs SDK | App | [Configure a scale rule](scale-app.md#custom) for each event source. |
4141

42+
## Concepts
43+
44+
A Container Apps environment is a secure boundary around one or more container apps and jobs. Jobs involve a few key concepts:
45+
46+
* **Job:** A job defines the default configuration that is used for each job execution. The configuration includes the container image to use, the resources to allocate, and the command to run.
47+
* **Job execution:** A job execution is a single run of a job that is triggered manually, on a schedule, or in response to an event.
48+
* **Job replica:** A typical job execution runs one replica defined by the job's configuration. In advanced scenarios, a job execution can run multiple replicas.
49+
50+
:::image type="content" source="media/jobs/azure-container-apps-jobs-overview.png" alt-text="Azure Container Apps jobs overview.":::
51+
4252
## Job trigger types
4353

4454
A job's trigger type determines how the job is started. The following trigger types are available:
@@ -49,7 +59,7 @@ A job's trigger type determines how the job is started. The following trigger ty
4959

5060
### Manual jobs
5161

52-
Manual jobs are triggered on-demand using the Azure CLI or a request to the Azure Resource Manager API.
62+
Manual jobs are triggered on-demand using the Azure CLI, Azure portal, or a request to the Azure Resource Manager API.
5363

5464
Examples of manual jobs include:
5565

@@ -66,7 +76,7 @@ To create a manual job using the Azure CLI, use the `az containerapp job create`
6676
az containerapp job create \
6777
--name "my-job" --resource-group "my-resource-group" --environment "my-environment" \
6878
--trigger-type "Manual" \
69-
--replica-timeout 1800 --replica-retry-limit 0 --replica-completion-count 1 --parallelism 1 \
79+
--replica-timeout 1800 \
7080
--image "mcr.microsoft.com/k8se/quickstart-jobs:latest" \
7181
--cpu "0.25" --memory "0.5Gi"
7282
```
@@ -141,7 +151,7 @@ Container Apps jobs use cron expressions to define schedules. It supports the st
141151
| `0 0 * * 0` | Runs every Sunday at midnight. |
142152
| `0 0 1 * *` | Runs on the first day of every month at midnight. |
143153

144-
Cron expressions in scheduled jobs are evaluated in Universal Time Coordinated (UTC).
154+
Cron expressions in scheduled jobs are evaluated in Coordinated Universal Time (UTC).
145155

146156
# [Azure CLI](#tab/azure-cli)
147157

@@ -151,7 +161,7 @@ To create a scheduled job using the Azure CLI, use the `az containerapp job crea
151161
az containerapp job create \
152162
--name "my-job" --resource-group "my-resource-group" --environment "my-environment" \
153163
--trigger-type "Schedule" \
154-
--replica-timeout 1800 --replica-retry-limit 0 --replica-completion-count 1 --parallelism 1 \
164+
--replica-timeout 1800 \
155165
--image "mcr.microsoft.com/k8se/quickstart-jobs:latest" \
156166
--cpu "0.25" --memory "0.5Gi" \
157167
--cron-expression "*/1 * * * *"
@@ -223,7 +233,7 @@ Event-driven jobs are triggered by events from supported [custom scalers](scale-
223233

224234
Container apps and event-driven jobs use [KEDA](https://keda.sh/) scalers. They both evaluate scaling rules on a polling interval to measure the volume of events for an event source, but the way they use the results is different.
225235

226-
In an app, each replica continuously processes events and a scaling rule determines the number of replicas to run to meet demand. In event-driven jobs, each job typically processes a single event, and a scaling rule determines the number of jobs to run.
236+
In an app, each replica continuously processes events and a scaling rule determines the number of replicas to run to meet demand. In event-driven jobs, each job execution typically processes a single event, and a scaling rule determines the number of job executions to run.
227237

228238
Use jobs when each event requires a new instance of the container with dedicated resources or needs to run for a long time. Event-driven jobs are conceptually similar to [KEDA scaling jobs](https://keda.sh/docs/latest/concepts/scaling-jobs/).
229239

@@ -237,7 +247,7 @@ To create an event-driven job using the Azure CLI, use the `az containerapp job
237247
az containerapp job create \
238248
--name "my-job" --resource-group "my-resource-group" --environment "my-environment" \
239249
--trigger-type "Event" \
240-
--replica-timeout 1800 --replica-retry-limit 0 --replica-completion-count 1 --parallelism 1 \
250+
--replica-timeout 1800 \
241251
--image "docker.io/myuser/my-event-driven-job:latest" \
242252
--cpu "0.25" --memory "0.5Gi" \
243253
--min-executions "0" \
@@ -341,13 +351,13 @@ To start a job execution using the Azure Resource Manager REST API, make a `POST
341351
The following example starts an execution of a job named `my-job` in a resource group named `my-resource-group`:
342352

343353
```http
344-
POST https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-resource-group/providers/Microsoft.App/jobs/my-job/start?api-version=2022-11-01-preview
354+
POST https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-resource-group/providers/Microsoft.App/jobs/my-job/start?api-version=2023-05-01
345355
Authorization: Bearer <TOKEN>
346356
```
347357

348358
Replace `<SUBSCRIPTION_ID>` with your subscription ID.
349359

350-
To authenticate the request, replace `<TOKEN>` in the `Authorization` header with a valid bearer token. For more information, see [Azure REST API reference](/rest/api/azure).
360+
To authenticate the request, replace `<TOKEN>` in the `Authorization` header with a valid bearer token. The identity used to generate the token must have `Contributor` permission to the Container Apps job resource. For more information, see [Azure REST API reference](/rest/api/azure).
351361

352362
# [Azure portal](#tab/azure-portal)
353363

@@ -357,6 +367,9 @@ To start a job execution in the Azure portal, select **Run now** in the job's ov
357367

358368
When you start a job execution, you can choose to override the job's configuration. For example, you can override an environment variable or the startup command to run the same job with different inputs. The overridden configuration is only used for the current execution and doesn't change the job's configuration.
359369

370+
> [!IMPORTANT]
371+
> When overriding the configuration, the job's entire template configuration is replaced with the new configuration. Ensure that the new configuration includes all required settings.
372+
360373
# [Azure CLI](#tab/azure-cli)
361374

362375
To override the job's configuration while starting an execution, use the `az containerapp job start` command and pass a YAML file containing the template to use for the execution. The following example starts an execution of a job named `my-job` in a resource group named `my-resource-group`.
@@ -367,6 +380,8 @@ Retrieve the job's current configuration with the `az containerapp job show` com
367380
az containerapp job show --name "my-job" --resource-group "my-resource-group" --query "properties.template" --output yaml > my-job-template.yaml
368381
```
369382

383+
The `--query "properties.template"` option returns only the job's template configuration.
384+
370385
Edit the `my-job-template.yaml` file to override the job's configuration. For example, to override the environment variables, modify the `env` section:
371386

372387
```yaml
@@ -397,7 +412,7 @@ az containerapp job start --name "my-job" --resource-group "my-resource-group" \
397412
To override the job's configuration, include a template in the request body. The following example overrides the startup command to run a different command:
398413

399414
```http
400-
POST https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-resource-group/providers/Microsoft.App/jobs/my-job/start?api-version=2022-11-01-preview
415+
POST https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-resource-group/providers/Microsoft.App/jobs/my-job/start?api-version=2023-05-01
401416
Content-Type: application/json
402417
Authorization: Bearer <TOKEN>
403418
@@ -421,7 +436,7 @@ Authorization: Bearer <TOKEN>
421436
}
422437
```
423438

424-
Replace `<SUBSCRIPTION_ID>` with your subscription ID and `<TOKEN>` in the `Authorization` header with a valid bearer token. For more information, see [Azure REST API reference](/rest/api/azure).
439+
Replace `<SUBSCRIPTION_ID>` with your subscription ID and `<TOKEN>` in the `Authorization` header with a valid bearer token. The identity used to generate the token must have `Contributor` permission to the Container Apps job resource. For more information, see [Azure REST API reference](/rest/api/azure).
425440

426441
# [Azure portal](#tab/azure-portal)
427442

@@ -446,7 +461,7 @@ az containerapp job execution list --name "my-job" --resource-group "my-resource
446461
To get the status of job executions using the Azure Resource Manager REST API, make a `GET` request to the job's `executions` operation. The following example returns the status of the most recent execution of a job named `my-job` in a resource group named `my-resource-group`:
447462

448463
```http
449-
GET https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-resource-group/providers/Microsoft.App/jobs/my-job/executions?api-version=2022-11-01-preview
464+
GET https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-resource-group/providers/Microsoft.App/jobs/my-job/executions?api-version=2023-05-01
450465
```
451466

452467
Replace `<SUBSCRIPTION_ID>` with your subscription ID.
@@ -469,7 +484,7 @@ Container Apps jobs support advanced configuration options such as container set
469484

470485
### Container settings
471486

472-
Container settings define the containers to run in each replica of a job execution. They include environment variables, secrets, and resource limits. For more information, see [Containers](containers.md).
487+
Container settings define the containers to run in each replica of a job execution. They include environment variables, secrets, and resource limits. For more information, see [Containers](containers.md). Running multiple containers in a single job is an advanced scenario. Most jobs run a single container.
473488

474489
### Job settings
475490

@@ -478,10 +493,11 @@ The following table includes the job settings that you can configure:
478493
| Setting | Azure Resource Manager property | CLI parameter| Description |
479494
|---|---|---|---|
480495
| Job type | `triggerType` | `--trigger-type` | The type of job. (`Manual`, `Schedule`, or `Event`) |
481-
| Parallelism | `parallelism` | `--parallelism` | The number of replicas to run per execution. For most jobs, set the value to `1`. |
482-
| Replica completion count | `replicaCompletionCount` | `--replica-completion-count` | The number of replicas to complete successfully for the execution to succeed. For most jobs, set the value to `1`. |
483496
| Replica timeout | `replicaTimeout` | `--replica-timeout` | The maximum time in seconds to wait for a replica to complete. |
497+
| Polling interval | `pollingInterval` | `--polling-interval` | The time in seconds to wait between polling for events. Default is 30 seconds. |
484498
| Replica retry limit | `replicaRetryLimit` | `--replica-retry-limit` | The maximum number of times to retry a failed replica. To fail a replica without retrying, set the value to `0`. |
499+
| Parallelism | `parallelism` | `--parallelism` | The number of replicas to run per execution. For most jobs, set the value to `1`. |
500+
| Replica completion count | `replicaCompletionCount` | `--replica-completion-count` | The number of replicas to complete successfully for the execution to succeed. Most be equal or less than the parallelism. For most jobs, set the value to `1`. |
485501

486502
### Example
487503

112 KB
Loading

articles/container-apps/tutorial-event-driven-jobs.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ In this tutorial, you learn how to work with [event-driven jobs](jobs.md#event-d
2323
> * Deploy the job to the Container Apps environment
2424
> * Verify that the queue messages are processed by the container app
2525
26-
The job you create starts an execution for each message that is sent to an Azure Storage Queue. Each job execution runs a container that performs the following steps:
26+
The job you create starts an execution for each message that is sent to an Azure Storage queue. Each job execution runs a container that performs the following steps:
2727

28-
1. Dequeues one message from the queue.
28+
1. Gets one message from the queue.
2929
1. Logs the message to the job execution logs.
3030
1. Deletes the message from the queue.
3131
1. Exits.
3232

33+
> [!IMPORTANT]
34+
> The scaler monitors the queue's length to determine how many jobs to start. For accurate scaling, don't delete a message from the queue until the job execution has finished processing it.
35+
3336
The source code for the job you run in this tutorial is available in an Azure Samples [GitHub repository](https://github.com/Azure-Samples/container-apps-event-driven-jobs-tutorial/blob/main/index.js).
3437

3538
[!INCLUDE [container-apps-create-cli-steps-jobs.md](../../includes/container-apps-create-cli-steps-jobs.md)]
@@ -117,9 +120,6 @@ To deploy the job, you must first build a container image for the job and push i
117120
--environment "$ENVIRONMENT" \
118121
--trigger-type "Event" \
119122
--replica-timeout "1800" \
120-
--replica-retry-limit "1" \
121-
--replica-completion-count "1" \
122-
--parallelism "1" \
123123
--min-executions "0" \
124124
--max-executions "10" \
125125
--polling-interval "60" \
@@ -140,9 +140,6 @@ To deploy the job, you must first build a container image for the job and push i
140140
| Parameter | Description |
141141
| --- | --- |
142142
| `--replica-timeout` | The maximum duration a replica can execute. |
143-
| `--replica-retry-limit` | The number of times to retry a replica. |
144-
| `--replica-completion-count` | The number of replicas to complete successfully before a job execution is considered successful. |
145-
| `--parallelism` | The number of replicas to start per job execution. |
146143
| `--min-executions` | The minimum number of job executions to run per polling interval. |
147144
| `--max-executions` | The maximum number of job executions to run per polling interval. |
148145
| `--polling-interval` | The polling interval at which to evaluate the scale rule. |

0 commit comments

Comments
 (0)