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
# Job preparation and release tasks on Batch compute nodes
11
11
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 to do 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.
13
13
14
-
- A job preparation task runs before a job's tasks run, on all compute nodes scheduled to run at least one task.
14
+
- A job preparation task runs before a job's tasks, on all compute nodes scheduled to run at least one task.
15
15
- A job release task runs once the job is completed, on each node in the pool that executed at least one task.
16
16
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 [resource file download](/dotnet/api/microsoft.azure.batch.jobpreparationtask.resourcefiles), elevated execution, custom environment variables, maximum execution duration, retry count, and file retention time.
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:
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.
20
27
@@ -25,17 +32,17 @@ This article shows how to use the [JobPreparationTask](/dotnet/api/microsoft.azu
25
32
26
33
Job preparation and job release tasks are a good fit for the following situations:
27
34
28
-
-**Download common task data**. Batch jobs often require a common set of data as input for a job's tasks. 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.
29
36
30
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.
31
38
32
-
-**Job and task output deletion**. 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.
39
+
-**Job and task output deletion**. 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.
33
40
34
41
-**Log retention**. 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).
35
42
36
43
## Job preparation task
37
44
38
-
Before running 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.
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.
39
46
40
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.
To see job preparation and release tasks in action, build 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 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:
100
107
101
108
1. Creates a pool with two nodes.
102
109
1. Creates a job with job preparation, release, and standard tasks.
103
110
1. Runs the job preparation task, which first writes the node ID to a text file in a node's *shared* directory.
104
111
1. Runs a task on each node that writes its task ID to the same text file.
105
112
1. Once all tasks are completed or the timeout is reached, prints the contents of each node's text file to the console.
106
-
1.When the job is completed, runs the job release task to delete the file from the node.
113
+
1.Runs the job release task to delete the file from the node when the job is completed.
107
114
1. Prints the exit codes of the job preparation and release tasks for each node they ran on.
108
115
1. Pauses execution to allow confirmation of job and/or pool deletion.
109
116
110
-
Output from the sample application is similar to the following:
117
+
Output from the sample application is similar to the following example:
111
118
112
119
```output
113
120
Attempting to create pool: JobPrepReleaseSamplePool
@@ -153,11 +160,11 @@ Sample complete, hit ENTER to exit...
153
160
```
154
161
155
162
> [!NOTE]
156
-
> Because the variable creation and start time of nodes in a new pool means some nodes are ready for tasks before others, 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, you sees that the job preparation and release tasks don't exist for the node that ran no tasks.
163
+
> Because the variable creation and start time of nodes in a new pool means some nodes are ready for tasks before others, 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.
157
164
158
165
## View job preparation and release tasks in the Azure portal
159
166
160
-
You can use the [Azure portal](https://portal.azure.com) to view Batch job properties and tasks, including preparation tasks and release tasks. Navigate to the job page after your tasks have completed, but before deleting your job and pool.
167
+
You can use the [Azure portal](https://portal.azure.com) to view Batch job properties and tasks, including job preparation tasks and release tasks. Navigate to the job page after your tasks have completed, but before deleting your job and pool.
161
168
162
169
The following screenshot shows the **JobPrepReleaseSampleJob** page after you run the sample application. Because the job has preparation tasks, you can select **Preparation tasks** in the left navigation on the job page to see their properties. You can also download the shared text file that the job tasks modify by selecting **Tasks** in the left navigation.
0 commit comments