You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/container-apps/tutorial-event-driven-jobs.md
+45-45Lines changed: 45 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,40 @@
1
1
---
2
-
title: 'Tutorial: Deploy an event-driven job with Azure Container Apps'
3
-
description: Learn to create a job that processes queue messages with Azure Container Apps
2
+
title: 'Tutorial: Deploy an Event-Driven Job with Azure Container Apps'
3
+
description: Learn how to create a job that processes queue messages by using Azure Container Apps.
4
4
services: container-apps
5
5
author: craigshoemaker
6
6
ms.service: azure-container-apps
7
7
ms.topic: conceptual
8
-
ms.date: 12/09/2024
8
+
ms.date: 02/02/2026
9
9
ms.author: cshoe
10
10
ms.custom:
11
11
- build-2023
12
12
- devx-track-azurecli
13
13
- sfi-ropc-nochange
14
14
---
15
15
16
-
# Tutorial: Deploy an event-driven job with Azure Container Apps
16
+
# Tutorial: Deploy an event-driven job by using Azure Container Apps
17
17
18
-
Azure Container Apps [jobs](jobs.md)allow you to run containerized tasks that execute for a finite duration and exit. You can trigger a job execution manually, on a schedule, or based on events. Jobs are best suited to for tasks such as data processing, machine learning, resource cleanup, or any scenario that requires serverless ephemeral compute resources.
18
+
Azure Container Apps [jobs](jobs.md)enable you to run containerized tasks that run for a finite duration and then stop. You can trigger a job execution manually, on a schedule, or based on events. Jobs are best suited to for tasks such as data processing, machine learning, resource cleanup, or any scenario that requires serverless ephemeral compute resources.
19
19
20
20
In this tutorial, you learn how to work with [event-driven jobs](jobs.md#event-driven-jobs).
21
21
22
22
> [!div class="checklist"]
23
-
> * Create a Container Apps environment to deploy your container apps
24
-
> * Create an Azure Storage Queue to send messages to the container app
23
+
> * Create a Container Apps environment in which to deploy your container apps
24
+
> * Create an Azure Storage queue to send messages to the container app
25
25
> * Build a container image that runs a job
26
26
> * Deploy the job to the Container Apps environment
27
27
> * Verify that the queue messages are processed by the container app
28
28
29
-
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:
29
+
The job you create starts an execution for each message that's sent to an Azure Storage queue. Each job execution runs a container that performs the following steps:
30
30
31
31
1. Gets one message from the queue.
32
32
1. Logs the message to the job execution logs.
33
33
1. Deletes the message from the queue.
34
-
1.Exits.
34
+
1.Stops.
35
35
36
36
> [!IMPORTANT]
37
-
> 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.
37
+
> 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 finishes processing it.
38
38
39
39
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).
40
40
@@ -46,12 +46,12 @@ The job uses an Azure Storage queue to receive messages. In this section, you cr
46
46
47
47
1. Define a name for your storage account.
48
48
49
-
```bash
49
+
```azurecli
50
50
STORAGE_ACCOUNT_NAME="<STORAGE_ACCOUNT_NAME>"
51
51
QUEUE_NAME="myqueue"
52
52
```
53
53
54
-
Replace `<STORAGE_ACCOUNT_NAME>` with a unique name foryour storage account. Storage account names must be *unique within Azure* and be from 3 to 24 charactersin length containing numbers and lowercase letters only.
54
+
Replace `<STORAGE_ACCOUNT_NAME>` with a unique name for your storage account. Storage account names must be unique within Azure. They must be between 3 and 24 characters long and contain numbers and lowercase letters only.
55
55
56
56
1. Create an Azure Storage account.
57
57
@@ -64,27 +64,27 @@ The job uses an Azure Storage queue to receive messages. In this section, you cr
64
64
--kind StorageV2
65
65
```
66
66
67
-
If this command returns the error:
67
+
If this command returns the following error, be sure you have registered the `Microsoft.Storage` namespace in your Azure subscription.
68
68
69
69
```
70
70
(SubscriptionNotFound) Subscription <SUBSCRIPTION_ID> was not found.
71
71
Code: SubscriptionNotFound
72
72
Message: Subscription <SUBSCRIPTION_ID> was not found.
73
73
```
74
74
75
-
Be sure you have registered the `Microsoft.Storage`namespacein your Azure subscription.
75
+
Use this command to register the namespace:
76
76
77
77
```azurecli
78
78
az provider register --namespace Microsoft.Storage
79
79
```
80
80
81
-
1. Save the queue's connection string into a variable.
81
+
1. Save the queue's connection string into a variable:
@@ -95,11 +95,11 @@ The job uses an Azure Storage queue to receive messages. In this section, you cr
95
95
96
96
## Create a user-assigned managed identity
97
97
98
-
To avoid using administrative credentials, pull images from private repositories in Microsoft Azure Container Registry using managed identities for authentication. When possible, use a user-assigned managed identity to pull images.
98
+
To avoid using administrative credentials, pull images from private repositories in Azure Container Registry. Use managed identities for authentication. When possible, use a user-assigned managed identity to pull images.
99
99
100
-
1. Create a user-assigned managed identity. Before you run the following commands, choose a name for your managed identity and replace the `\<PLACEHOLDER\>` with the name.
100
+
1. Create a user-assigned managed identity. Before you run the following commands, choose a name for your managed identity and create the following variable:
101
101
102
-
```bash
102
+
```azurecli
103
103
IDENTITY="<YOUR_IDENTITY_NAME>"
104
104
```
105
105
@@ -109,7 +109,7 @@ To avoid using administrative credentials, pull images from private repositories
109
109
--resource-group $RESOURCE_GROUP
110
110
```
111
111
112
-
1. Get the identity's resource ID.
112
+
1. Get the identity's resource ID:
113
113
114
114
```azurecli
115
115
IDENTITY_ID=$(az identity show \
@@ -121,18 +121,18 @@ To avoid using administrative credentials, pull images from private repositories
121
121
122
122
## Build and deploy the job
123
123
124
-
To deploy the job, you must first build a container image forthe job and push it to a registry. Then, you can deploy the job to the Container Apps environment.
124
+
To deploy the job, you must first build a container image for it and push the container to a registry. You can then deploy the job to the Container Apps environment.
125
125
126
-
1. Define a name for your container image and registry.
126
+
1. Define a name for your container image and registry:
Replace `<CONTAINER_REGISTRY_NAME>` with a unique name foryour container registry. Container registry names must be *unique within Azure* and be from 5 to 50 charactersin length containing numbers and lowercase letters only.
133
+
Replace `<CONTAINER_REGISTRY_NAME>` with a unique name for your container registry. Container registry names must be unique within Azure. They must be between 5 and 50 characters long and contain numbers and lowercase letters only.
134
134
135
-
1. Create a container registry.
135
+
1. Create a container registry:
136
136
137
137
```azurecli
138
138
az acr create \
@@ -144,27 +144,27 @@ To deploy the job, you must first build a container image for the job and push i
144
144
145
145
1. Your container registry must allow Azure Resource Manager (ARM) audience tokens for authentication in order to use managed identity to pull images.
146
146
147
-
Use the following command to check if ARM tokens are allowed to access your Azure Container Registry (ACR).
147
+
Use the following command to check whether ARM tokens are allowed to access your Azure container registry:
148
148
149
149
```azurecli
150
150
az acr config authentication-as-arm show --registry "$CONTAINER_REGISTRY_NAME"
151
151
```
152
152
153
-
If ARM tokens are allowed, the command outputs the following.
153
+
If ARM tokens are allowed, you see the following output:
154
154
155
155
```
156
156
{
157
157
"status": "enabled"
158
158
}
159
159
```
160
160
161
-
If the `status` is `disabled`, allow ARM tokens with the following command.
161
+
If the `status` is `disabled`, allow ARM tokens by using the following command:
162
162
163
163
```azurecli
164
164
az acr config authentication-as-arm update --registry "$CONTAINER_REGISTRY_NAME" --status enabled
165
165
```
166
166
167
-
1. The source code forthe job is available on [GitHub](https://github.com/Azure-Samples/container-apps-event-driven-jobs-tutorial). Run the following command to clone the repository and build the container imagein the cloud using the `az acr build` command.
167
+
1. The source code for the job is available on [GitHub](https://github.com/Azure-Samples/container-apps-event-driven-jobs-tutorial). Run the following command to clone the repository and build the container image in the cloud:
168
168
169
169
```azurecli
170
170
az acr build \
@@ -175,7 +175,7 @@ To deploy the job, you must first build a container image for the job and push i
175
175
176
176
The image is now available in the container registry.
177
177
178
-
1. Create a job in the Container Apps environment.
178
+
1. Create a job in the Container Apps environment:
179
179
180
180
```azurecli
181
181
az containerapp job create \
@@ -201,11 +201,11 @@ To deploy the job, you must first build a container image for the job and push i
The following table describes the key parameters used in the command.
204
+
The following table describes the key parameters used in the previous command.
205
205
206
206
| Parameter | Description |
207
207
| --- | --- |
208
-
|`--replica-timeout`| The maximum duration a replica can execute. |
208
+
| `--replica-timeout` | The maximum duration a replica can run. |
209
209
| `--min-executions` | The minimum number of job executions to run per polling interval. |
210
210
| `--max-executions` | The maximum number of job executions to run per polling interval. |
211
211
| `--polling-interval` | The polling interval at which to evaluate the scale rule. |
@@ -214,22 +214,22 @@ To deploy the job, you must first build a container image for the job and push i
214
214
| `--scale-rule-metadata` | The metadata for the scale rule. |
215
215
| `--scale-rule-auth` | The authentication for the scale rule. |
216
216
| `--secrets` | The secrets to use for the job. |
217
-
|`--registry-server`| The container registry server to use for the job. For an Azure Container Registry, the command automatically configures authentication. |
217
+
| `--registry-server` | The container registry server to use for the job. For an Azure container registry, the command automatically configures authentication. |
218
218
| `--mi-user-assigned` | The resource ID of the user-assigned managed identity to assign to the job. |
219
-
|`--registry-identity`| The resource ID of a managed identity to authenticate with the registry server instead of using a username and password. If possible, an 'acrpull' role assignment is created for the identity automatically. |
219
+
| `--registry-identity` | The resource ID of a managed identity to authenticate with the registry server instead of using a user name and password. If possible, an `acrpull` role assignment is automatically created for the identity. |
220
220
| `--env-vars` | The environment variables to use for the job. |
221
221
222
-
The scale rule configuration defines the event source to monitor. It is evaluated on each polling interval and determines how many job executions to trigger. To learn more, see [Set scaling rules](scale-app.md).
222
+
The scale rule configuration defines the event source to monitor. It's evaluated on each polling interval and determines how many job executions to trigger. For more information, see [Set scaling rules](scale-app.md).
223
223
224
224
The event-driven job is now created in the Container Apps environment.
225
225
226
226
## Verify the deployment
227
227
228
-
The job is configured to evaluate the scale rule every 60 seconds, which checks the number of messages in the queue. For each evaluation period, it starts a new job execution foreach messagein the queue, up to a maximum of 10 executions.
228
+
The job is configured to evaluate the scale rule every 60 seconds. This evaluation checks the number of messages in the queue. For each evaluation period, it starts a new job execution for each message in the queue, up to a maximum of 10 executions.
229
229
230
-
To verify the job was configured correctly, you can send some messages to the queue, confirm that job executions are started, and the messages are logged to the job execution logs.
230
+
To verify that the job is configured correctly, you can send some messages to the queue and confirm that job executions are started and that the messages are logged to the job execution logs.
231
231
232
-
1. Send a message to the queue.
232
+
1. Send a message to the queue:
233
233
234
234
```azurecli
235
235
az storage message put \
@@ -238,7 +238,7 @@ To verify the job was configured correctly, you can send some messages to the qu
238
238
--connection-string "$QUEUE_CONNECTION_STRING"
239
239
```
240
240
241
-
1. List the executions of a job.
241
+
1. List the executions of a job:
242
242
243
243
```azurecli
244
244
az containerapp job execution list \
@@ -247,9 +247,9 @@ To verify the job was configured correctly, you can send some messages to the qu
247
247
--output json
248
248
```
249
249
250
-
Since the job is configured to evaluate the scale rule every 60 seconds, it may take up to a full minute for the job execution to start. Repeat the commanduntil you see the job execution and its status is `Succeeded`.
250
+
Because the job is configured to evaluate the scale rule every 60 seconds, it might take up to a full minute for the job execution to start. Repeat the command until you see the job execution and its status is `Succeeded`.
251
251
252
-
1. Run the following commands to see logged messages. These commands require the Log analytics extension, so accept the prompt to install extension when requested.
252
+
1. Run the following commands to see logged messages. These commands require the Log analytics extension, so accept the prompt to install the extension.
@@ -262,21 +262,21 @@ To verify the job was configured correctly, you can send some messages to the qu
262
262
Until the `ContainerAppConsoleLogs_CL` table is ready, the command returns an error: `BadArgumentError: The request had some invalid properties`. Wait a few minutes and try again.
263
263
264
264
> [!TIP]
265
-
> Having issues? Let us know on GitHub by opening an issue in the [Azure Container Apps repo](https://github.com/microsoft/azure-container-apps).
265
+
> Having problems? Let us know on GitHub by opening an issue in the [Azure Container Apps repo](https://github.com/microsoft/azure-container-apps).
266
266
267
267
## Clean up resources
268
268
269
-
Once you're done, run the following command to delete the resource group that contains your Container Apps resources.
269
+
When you're done, run the following command to delete the resource group that contains your Container Apps resources.
270
270
271
271
>[!CAUTION]
272
-
> The following command deletes the specified resource group and all resources contained within it. If resources outside the scope of this tutorial exist in the specified resource group, they will also be deleted.
272
+
> The following command deletes the specified resource group and all resources contained in it. If there are resources outside the scope of this tutorial in the specified resource group, they're also deleted.
0 commit comments