Skip to content

Commit 4403e6c

Browse files
Merge pull request #233742 from v-thepet/batch4
Freshness Pass for User Story: 79612 (4)
2 parents 1d12426 + 292ea3f commit 4403e6c

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed

articles/batch/batch-job-prep-release.md

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,70 @@
11
---
2-
title: Create tasks to prepare and complete jobs on compute nodes
3-
description: Make job-level preparation tasks to minimize data transfer to Azure Batch compute nodes, and release tasks for node cleanup at job completion.
2+
title: Job preparation and release tasks on Batch compute nodes
3+
description: Use job-level preparation tasks to minimize data transfer to Azure Batch compute nodes, and release tasks for node cleanup at job completion.
44
ms.topic: how-to
5-
ms.date: 01/12/2021
5+
ms.date: 04/06/2023
66
ms.devlang: csharp
77
ms.custom: "seodec18, devx-track-csharp"
88

99
---
10-
# Create tasks to prepare and complete jobs on Batch compute nodes
10+
# Job preparation and release tasks on Batch compute nodes
1111

12-
An Azure Batch job often requires some form of setup before its tasks are executed. It also may require post-job maintenance when its tasks are completed. For example, you might need to download common task input data to your compute nodes, or upload task output data to Azure Storage after the job completes. You can use **job preparation** and **job release** tasks to perform these operations.
12+
An Azure Batch job often requires setup before its tasks are executed, and post-job maintenance when its tasks are completed. For example, you might need to download common task input data to your compute nodes, or upload task output data to Azure Storage after the job completes. You can use *job preparation* and *job release* tasks for these operations.
1313

14-
## What are job preparation and release tasks?
14+
- A job preparation task runs before a job's tasks, on all compute nodes scheduled to run at least one task.
15+
- A job release task runs once the job is completed, on each node in the pool that executed at least one task.
1516

16-
Before a job's tasks run, the job preparation task runs on all compute nodes scheduled to run at least one task. Once the job is completed, the job release task runs on each node in the pool that executed at least one task. As with normal Batch tasks, you can specify a command line to be invoked when a job preparation or release task is run.
17+
As with other Batch tasks, you can specify a command line to invoke when a job preparation or release task runs. Job preparation and release tasks offer familiar Batch task features such as:
1718

18-
Job preparation and release tasks offer familiar Batch task features such as file download ([resource files](/dotnet/api/microsoft.azure.batch.jobpreparationtask.resourcefiles)), elevated execution, custom environment variables, maximum execution duration, retry count, and file retention time.
19+
- [Resource file download](/dotnet/api/microsoft.azure.batch.jobpreparationtask.resourcefiles).
20+
- Elevated execution.
21+
- Custom environment variables.
22+
- Maximum execution duration.
23+
- Retry count.
24+
- File retention time.
1925

20-
In the following sections, you'll learn how to use the [JobPreparationTask](/dotnet/api/microsoft.azure.batch.jobpreparationtask) and [JobReleaseTask](/dotnet/api/microsoft.azure.batch.jobreleasetask) classes found in the [Batch .NET](/dotnet/api/microsoft.azure.batch) library.
26+
This article shows how to use the [JobPreparationTask](/dotnet/api/microsoft.azure.batch.jobpreparationtask) and [JobReleaseTask](/dotnet/api/microsoft.azure.batch.jobreleasetask) classes in the [Batch .NET](/dotnet/api/microsoft.azure.batch) library.
2127

2228
> [!TIP]
23-
> Job preparation and release tasks are especially helpful in "shared pool" environments, in which a pool of compute nodes persists between job runs and is used by many jobs.
29+
> Job preparation and release tasks are especially helpful in *shared pool* environments, in which a pool of compute nodes persists between job runs and is used by many jobs.
2430
25-
## When to use job preparation and release tasks
31+
## Use cases for job preparation and release tasks
2632

27-
Job preparation and job release tasks are a good fit for the following situations:
33+
Job preparation and job release tasks are a good fit for the following scenarios:
2834

29-
- **Downloading common task data**: Batch jobs often require a common set of data as input for the job's tasks. For example, in daily risk analysis calculations, market data is job-specific, yet common to all tasks in the job. This market data, often several gigabytes in size, should be downloaded to each compute node only once so that any task that runs on the node can use it. Use a **job preparation task** to download this data to each node before the execution of the job's other tasks.
35+
- **Download common task data**. Batch jobs often require a common set of data as input for a job's tasks. You can use a job preparation task to download this data to each node before the execution of the job's other tasks.
3036

31-
- **Job and task output deletion**: In a "shared pool" environment, where a pool's compute nodes are not decommissioned between jobs, you may need to delete job data between runs. You might need to conserve disk space on the nodes, or satisfy your organization's security policies. Use a **job release task** to delete data that was downloaded by a job preparation task, or that was generated during task execution.
37+
For example, in daily risk analysis calculations, market data is job-specific yet common to all tasks in the job. You can use a job preparation task to download this market data, which is often several gigabytes in size, to each compute node so that any task that runs on the node can use it.
3238

33-
- **Log retention**: You might want to keep a copy of log files that your tasks generate, or perhaps crash dump files that can be generated by failed applications. Use a **job release task** in such cases to compress and upload this data to an [Azure Storage account](accounts.md#azure-storage-accounts).
39+
- **Delete job and task output**. In a shared pool environment, where a pool's compute nodes aren't decommissioned between jobs, you might need to delete job data between runs. For example, you might need to conserve disk space on the nodes, or satisfy your organization's security policies. You can use a job release task to delete data that a job preparation task downloaded or that task execution generated.
40+
41+
- **Retain logs**. You might want to keep a copy of log files that your tasks generate, or crash dump files that failed applications generate. You can use a job release task to compress and upload this data to an [Azure Storage account](accounts.md#azure-storage-accounts).
3442

3543
## Job preparation task
3644

37-
Before executing tasks in a job, Batch runs the job preparation task on each compute node scheduled to run a task. By default, Batch waits for the job preparation task to complete before running the tasks scheduled to execute on the node. However, you can configure the service not to wait. If the node restarts, the job preparation task runs again. You can also disable this behavior. If you have a job with a job preparation task and a job manager task configured, the job preparation task runs before the job manager task, just as it does for all other tasks. The job preparation task always runs first.
45+
Before it runs job tasks, Batch runs the job preparation task on each compute node scheduled to run a task. By default, Batch waits for the job preparation task to complete before running scheduled job tasks, but you can configure it not to wait.
46+
47+
If the node restarts, the job preparation task runs again, but you can also disable this behavior. If you have a job with a job preparation task and a job manager task, the job preparation task runs before the job manager task and before all other tasks. The job preparation task always runs first.
3848

39-
The job preparation task is executed only on nodes that are scheduled to run a task. This prevents the unnecessary execution of a preparation task in case a node is not assigned any tasks. This can occur when the number of tasks for a job is less than the number of nodes in a pool. It also applies when [concurrent task execution](batch-parallel-node-tasks.md) is enabled, which leaves some nodes idle if the task count is lower than the total possible concurrent tasks.
49+
The job preparation task runs only on nodes that are scheduled to run a task. This behavior prevents unnecessary runs on nodes that aren't assigned any tasks. Nodes might not be assigned any tasks when the number of job tasks is less than the number of nodes in the pool. This behavior also applies when [concurrent task execution](batch-parallel-node-tasks.md) is enabled, which leaves some nodes idle if the task count is lower than the total possible concurrent tasks.
4050

4151
> [!NOTE]
42-
> [JobPreparationTask](/dotnet/api/microsoft.azure.batch.cloudjob.jobpreparationtask) differs from [CloudPool.StartTask](/dotnet/api/microsoft.azure.batch.cloudpool.starttask) in that JobPreparationTask executes at the start of each job, whereas StartTask executes only when a compute node first joins a pool or restarts.
52+
> [JobPreparationTask](/dotnet/api/microsoft.azure.batch.cloudjob.jobpreparationtask) differs from [CloudPool.StartTask](/dotnet/api/microsoft.azure.batch.cloudpool.starttask) in that `JobPreparationTask` runs at the start of each job, whereas `StartTask` runs only when a compute node first joins a pool or restarts.
4353
4454
## Job release task
4555

46-
Once a job is marked as completed, the job release task runs on each node in the pool that executed at least one task. You mark a job as completed by issuing a terminate request. This request sets the job state to *terminating*, terminates any active or running tasks associated with the job, and runs the job release task. The job then moves to the *completed* state.
56+
Once you mark a job as completed, the job release task runs on each node in the pool that ran at least one task. You mark a job as completed by issuing a terminate request. This request sets the job state to *terminating*, terminates any active or running tasks associated with the job, and runs the job release task. The job then moves to the *completed* state.
4757

4858
> [!NOTE]
49-
> Deleting a job also executes the job release task. However, if a job has already been terminated, the release task is not run a second time if the job is later deleted.
59+
> Deleting a job also executes the job release task. However, if a job is already terminated, the release task doesn't run a second time if the job is later deleted.
5060
51-
Jobs release tasks can run for a maximum of 15 minutes before being terminated by the Batch service. For more information, see the [REST API reference documentation](/rest/api/batchservice/job/add#jobreleasetask).
61+
Job release tasks can run for a maximum of 15 minutes before the Batch service terminates them. For more information, see the [REST API reference documentation](/rest/api/batchservice/job/add#jobreleasetask).
5262

53-
## Job prep and release tasks with Batch .NET
63+
## Job preparation and release tasks with Batch .NET
5464

55-
To use a job preparation task, assign a [JobPreparationTask](/dotnet/api/microsoft.azure.batch.jobpreparationtask) object to your job's [CloudJob.JobPreparationTask](/dotnet/api/microsoft.azure.batch.cloudjob.jobpreparationtask) property. Similarly, to use a job release task, initialize a [JobReleaseTask](/dotnet/api/microsoft.azure.batch.jobreleasetask) and assign it to your job's [CloudJob.JobReleaseTask](/dotnet/api/microsoft.azure.batch.cloudjob.jobreleasetask).
65+
To run a job preparation task, assign a [JobPreparationTask](/dotnet/api/microsoft.azure.batch.jobpreparationtask) object to your job's [CloudJob.JobPreparationTask](/dotnet/api/microsoft.azure.batch.cloudjob.jobpreparationtask) property. Similarly, to use a job release task, initialize a [JobReleaseTask](/dotnet/api/microsoft.azure.batch.jobreleasetask) and assign it to your job's [CloudJob.JobReleaseTask](/dotnet/api/microsoft.azure.batch.cloudjob.jobreleasetask).
5666

57-
In this code snippet, `myBatchClient` is an instance of [BatchClient](/dotnet/api/microsoft.azure.batch.batchclient), and `myPool` is an existing pool within the Batch account.
67+
In the following code snippet, `myBatchClient` is an instance of [BatchClient](/dotnet/api/microsoft.azure.batch.batchclient), and `myPool` is an existing pool within the Batch account.
5868

5969
```csharp
6070
// Create the CloudJob for CloudPool "myPool"
@@ -80,33 +90,33 @@ myJob.JobReleaseTask =
8090
await myJob.CommitAsync();
8191
```
8292

83-
As mentioned earlier, the release task is executed when a job is terminated or deleted. Terminate a job with [JobOperations.TerminateJobAsync](/dotnet/api/microsoft.azure.batch.joboperations.terminatejobasync). Delete a job with [JobOperations.DeleteJobAsync](/dotnet/api/microsoft.azure.batch.joboperations.deletejobasync). You typically terminate or delete a job when its tasks are completed, or when a timeout that you've defined has been reached.
93+
The job release task runs when a job is terminated or deleted. You terminate a job by using [JobOperations.TerminateJobAsync](/dotnet/api/microsoft.azure.batch.joboperations.terminatejobasync), and delete a job by using [JobOperations.DeleteJobAsync](/dotnet/api/microsoft.azure.batch.joboperations.deletejobasync). You typically terminate or delete a job when its tasks are completed, or when a timeout you define is reached.
8494

8595
```csharp
86-
// Terminate the job to mark it as completed; this will initiate the
87-
// job release task on any node that executed job tasks. Note that the
88-
// job release task is also executed when a job is deleted, so you don't
96+
// Terminate the job to mark it as completed. Terminate initiates the
97+
// job release task on any node that ran job tasks. Note that the
98+
// job release task also runs when a job is deleted, so you don't
8999
// have to call Terminate if you delete jobs after task completion.
90100
91101
await myBatchClient.JobOperations.TerminateJobAsync("JobPrepReleaseSampleJob");
92102
```
93103

94104
## Code sample on GitHub
95105

96-
To see job preparation and release tasks in action, check out the [JobPrepRelease](https://github.com/Azure-Samples/azure-batch-samples/tree/master/CSharp/ArticleProjects/JobPrepRelease) sample project on GitHub. This console application does the following:
106+
To see job preparation and release tasks in action, build and run the [JobPrepRelease](https://github.com/Azure-Samples/azure-batch-samples/tree/master/CSharp/ArticleProjects/JobPrepRelease) sample project from GitHub. This console application takes the following actions:
97107

98108
1. Creates a pool with two nodes.
99109
1. Creates a job with job preparation, release, and standard tasks.
100-
1. Runs the job preparation task, which first writes the node ID to a text file in a node's "shared" directory.
110+
1. Runs the job preparation task, which first writes the node ID to a text file in a node's *shared* directory.
101111
1. Runs a task on each node that writes its task ID to the same text file.
102-
1. Once all tasks are completed (or the timeout is reached), prints the contents of each node's text file to the console.
103-
1. When the job is completed, runs the job release task to delete the file from the node.
104-
1. Prints the exit codes of the job preparation and release tasks for each node on which they executed.
112+
1. Once all tasks are completed or the timeout is reached, prints the contents of each node's text file to the console.
113+
1. Runs the job release task to delete the file from the node when the job is completed.
114+
1. Prints the exit codes of the job preparation and release tasks for each node they ran on.
105115
1. Pauses execution to allow confirmation of job and/or pool deletion.
106116

107-
Output from the sample application is similar to the following:
117+
Output from the sample application is similar to the following example:
108118

109-
```
119+
```output
110120
Attempting to create pool: JobPrepReleaseSamplePool
111121
Created pool JobPrepReleaseSamplePool with 2 nodes
112122
Checking for existing job JobPrepReleaseSampleJob...
@@ -150,15 +160,19 @@ Sample complete, hit ENTER to exit...
150160
```
151161

152162
> [!NOTE]
153-
> Due to the variable creation and start time of nodes in a new pool (some nodes are ready for tasks before others), you may see different output. Specifically, because the tasks complete quickly, one of the pool's nodes may execute all of the job's tasks. If this occurs, you will notice that the job prep and release tasks do not exist for the node that executed no tasks.
163+
> The varying creation and start times of nodes in a new pool means some nodes are ready for tasks before others, so you might see different output. Specifically, because the tasks complete quickly, one of the pool's nodes might run all of the job's tasks. If this occurs, the job preparation and release tasks don't exist for the node that ran no tasks.
164+
165+
## View job preparation and release tasks in the Azure portal
166+
167+
You can use the [Azure portal](https://portal.azure.com) to view Batch job properties and tasks, including job preparation and release tasks. From your Batch account page, select **Jobs** from the left navigation and then select a job. If you run the sample application, navigate to the job page after the tasks complete, but before you delete the job and pool.
154168

155-
### Inspect job preparation and release tasks in the Azure portal
169+
You can monitor job progress and status by expanding **Approximate task count** on the job **Overview** or **Tasks** page.
156170

157-
You can use the [Azure portal](https://portal.azure.com) to view the properties of the job and its tasks. After you run the sample application, you can also download the shared text file that is modified by the job's tasks.
171+
:::image type="content" source="media/batch-job-prep-release/monitor-tasks.png" alt-text="Screenshot showing job task progress in the Azure portal.":::
158172

159-
The screenshot below shows the **Preparation tasks blade** in the Azure portal. Navigate to the *JobPrepReleaseSampleJob* properties after your tasks have completed (but before deleting your job and pool) and click **Preparation tasks** or **Release tasks** to view their properties.
173+
The following screenshot shows the **JobPrepReleaseSampleJob** page after the sample application runs. This job had preparation and release tasks, so you can select **Preparation tasks** or **Release tasks** in the left navigation to see their properties.
160174

161-
:::image type="content" source="media/batch-job-prep-release/portal-jobprep-01.png" alt-text="Screenshot showing job preparation task properties in the Azure portal.":::
175+
:::image type="content" source="media/batch-job-prep-release/portal-jobprep-01.png" alt-text="Screenshot showing job release task properties in the Azure portal.":::
162176

163177
## Next steps
164178

44 KB
Loading
-13.4 KB
Loading

0 commit comments

Comments
 (0)