BatchTask Class
Batch will retry Tasks when a recovery operation is triggered on a Node. Examples of recovery operations include (but are not limited to) when an unhealthy Node is rebooted or a Compute Node disappeared due to host failure. Retries due to recovery operations are independent of and are not counted against the maxTaskRetryCount. Even if the maxTaskRetryCount is 0, an internal retry due to a recovery operation may occur. Because of this, all Tasks should be idempotent. This means Tasks need to tolerate being interrupted and restarted without causing any corruption or duplicate data. The best practice for long running Tasks is to use some form of checkpointing.
Constructor
BatchTask(*args: Any, **kwargs: Any)
Variables
| Name | Description |
|---|---|
|
id
|
A string that uniquely identifies the Task within the Job. The ID can contain any combination of alphanumeric characters including hyphens and underscores, and cannot contain more than 64 characters. Required. |
|
display_name
|
A display name for the Task. The display name need not be unique and can contain any Unicode characters up to a maximum length of 1024. |
|
url
|
The URL of the Task. Required. |
|
etag
|
The ETag of the Task. This is an opaque string. You can use it to detect whether the Task has changed between requests. In particular, you can be pass the ETag when updating a Task to specify that your changes should take effect only if nobody else has modified the Task in the meantime. Required. |
|
last_modified
|
The last modified time of the Task. Required. |
|
creation_time
|
The creation time of the Task. Required. |
|
exit_conditions
|
How the Batch service should respond when the Task completes. |
|
state
|
The current state of the Task. Required. Known values are: "active", "preparing", "running", and "completed". |
|
state_transition_time
|
The time at which the Task entered its current state. Required. |
|
previous_state
|
The previous state of the Task. This property is not set if the Task is in its initial Active state. Known values are: "active", "preparing", "running", and "completed". |
|
previous_state_transition_time
|
The time at which the Task entered its previous state. This property is not set if the Task is in its initial Active state. |
|
command_line
|
The command line of the Task. For multi-instance Tasks, the command line is executed as the primary Task, after the primary Task and all subtasks have finished executing the coordination command line. The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion. If you want to take advantage of such features, you should invoke the shell in the command line, for example using "cmd /c MyCommand" in Windows or "/bin/sh -c MyCommand" in Linux. If the command line refers to file paths, it should use a relative path (relative to the Task working directory), or use the Batch provided environment variable (https://learn.microsoft.com/azure/batch/batch-compute-node-environment-variables). Required. |
|
container_settings
|
The settings for the container under which the Task runs. If the Pool that will run this Task has containerConfiguration set, this must be set as well. If the Pool that will run this Task doesn't have containerConfiguration set, this must not be set. When this is specified, all directories recursively below the AZ_BATCH_NODE_ROOT_DIR (the root of Azure Batch directories on the node) are mapped into the container, all Task environment variables are mapped into the container, and the Task command line is executed in the container. Files produced in the container outside of AZ_BATCH_NODE_ROOT_DIR might not be reflected to the host disk, meaning that Batch file APIs will not be able to access those files. |
|
resource_files
|
A list of files that the Batch service will download to the Compute Node before running the command line. For multi-instance Tasks, the resource files will only be downloaded to the Compute Node on which the primary Task is executed. There is a maximum size for the list of resource files. When the max size is exceeded, the request will fail and the response error code will be RequestEntityTooLarge. If this occurs, the collection of ResourceFiles must be reduced in size. This can be achieved using .zip files, Application Packages, or Docker Containers. |
|
output_files
|
A list of files that the Batch service will upload from the Compute Node after running the command line. For multi-instance Tasks, the files will only be uploaded from the Compute Node on which the primary Task is executed. |
|
environment_settings
|
A list of environment variable settings for the Task. |
|
affinity_info
|
A locality hint that can be used by the Batch service to select a Compute Node on which to start the new Task. |
|
constraints
|
The execution constraints that apply to this Task. |
|
required_slots
|
The number of scheduling slots that the Task requires to run. The default is 1. A Task can only be scheduled to run on a compute node if the node has enough free scheduling slots available. For multi-instance Tasks, this must be 1. |
|
user_identity
|
The user identity under which the Task runs. If omitted, the Task runs as a non-administrative user unique to the Task. |
|
execution_info
|
Information about the execution of the Task. |
|
node_info
|
Information about the Compute Node on which the Task ran. |
|
multi_instance_settings
|
An object that indicates that the Task is a multi-instance Task, and contains information about how to run the multi-instance Task. |
|
task_statistics
|
Resource usage statistics for the Task. |
|
depends_on
|
The Tasks that this Task depends on. This Task will not be scheduled until all Tasks that it depends on have completed successfully. If any of those Tasks fail and exhaust their retry counts, this Task will never be scheduled. |
|
application_package_references
|
A list of Packages that the Batch service will deploy to the Compute Node before running the command line. Application packages are downloaded and deployed to a shared directory, not the Task working directory. Therefore, if a referenced package is already on the Node, and is up to date, then it is not re-downloaded; the existing copy on the Compute Node is used. If a referenced Package cannot be installed, for example because the package has been deleted or because download failed, the Task fails. |
Methods
| as_dict |
Return a dict that can be turned into json using json.dump. |
| clear |
Remove all items from D. |
| copy | |
| get |
Get the value for key if key is in the dictionary, else default. :param str key: The key to look up. :param any default: The value to return if key is not in the dictionary. Defaults to None :returns: D[k] if k in D, else d. :rtype: any |
| items | |
| keys | |
| pop |
Removes specified key and return the corresponding value. :param str key: The key to pop. :param any default: The value to return if key is not in the dictionary :returns: The value corresponding to the key. :rtype: any :raises KeyError: If key is not found and default is not given. |
| popitem |
Removes and returns some (key, value) pair :returns: The (key, value) pair. :rtype: tuple :raises KeyError: if D is empty. |
| setdefault |
Same as calling D.get(k, d), and setting D[k]=d if k not found :param str key: The key to look up. :param any default: The value to set if key is not in the dictionary :returns: D[k] if k in D, else d. :rtype: any |
| update |
Updates D from mapping/iterable E and F. :param any args: Either a mapping object or an iterable of key-value pairs. |
| values |
as_dict
Return a dict that can be turned into json using json.dump.
as_dict(*, exclude_readonly: bool = False) -> dict[str, Any]
Keyword-Only Parameters
| Name | Description |
|---|---|
|
exclude_readonly
|
Whether to remove the readonly properties. Default value: False
|
Returns
| Type | Description |
|---|---|
|
A dict JSON compatible object |
clear
Remove all items from D.
clear() -> None
copy
copy() -> Model
get
Get the value for key if key is in the dictionary, else default. :param str key: The key to look up. :param any default: The value to return if key is not in the dictionary. Defaults to None :returns: D[k] if k in D, else d. :rtype: any
get(key: str, default: Any = None) -> Any
Parameters
| Name | Description |
|---|---|
|
key
Required
|
|
|
default
|
Default value: None
|
items
items() -> ItemsView[str, Any]
Returns
| Type | Description |
|---|---|
|
set-like object providing a view on D's items |
keys
keys() -> KeysView[str]
Returns
| Type | Description |
|---|---|
|
a set-like object providing a view on D's keys |
pop
Removes specified key and return the corresponding value. :param str key: The key to pop. :param any default: The value to return if key is not in the dictionary :returns: The value corresponding to the key. :rtype: any :raises KeyError: If key is not found and default is not given.
pop(key: str, default: ~typing.Any = <object object>) -> Any
Parameters
| Name | Description |
|---|---|
|
key
Required
|
|
|
default
|
|
popitem
Removes and returns some (key, value) pair :returns: The (key, value) pair. :rtype: tuple :raises KeyError: if D is empty.
popitem() -> tuple[str, Any]
setdefault
Same as calling D.get(k, d), and setting D[k]=d if k not found :param str key: The key to look up. :param any default: The value to set if key is not in the dictionary :returns: D[k] if k in D, else d. :rtype: any
setdefault(key: str, default: ~typing.Any = <object object>) -> Any
Parameters
| Name | Description |
|---|---|
|
key
Required
|
|
|
default
|
|
update
Updates D from mapping/iterable E and F. :param any args: Either a mapping object or an iterable of key-value pairs.
update(*args: Any, **kwargs: Any) -> None
values
values() -> ValuesView[Any]
Returns
| Type | Description |
|---|---|
|
an object providing a view on D's values |
Attributes
affinity_info
A locality hint that can be used by the Batch service to select a Compute Node on which to start the new Task.
affinity_info: _models.BatchAffinityInfo | None
application_package_references
A list of Packages that the Batch service will deploy to the Compute Node before running the command line. Application packages are downloaded and deployed to a shared directory, not the Task working directory. Therefore, if a referenced package is already on the Node, and is up to date, then it is not re-downloaded; the existing copy on the Compute Node is used. If a referenced Package cannot be installed, for example because the package has been deleted or because download failed, the Task fails.
application_package_references: list['_models.BatchApplicationPackageReference'] | None
command_line
The command line of the Task. For multi-instance Tasks, the command line is executed as the primary Task, after the primary Task and all subtasks have finished executing the coordination command line. The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion. If you want to take advantage of such features, you should invoke the shell in the command line, for example using "cmd /c MyCommand" in Windows or "/bin/sh -c MyCommand" in Linux. If the command line refers to file paths, it should use a relative path (relative to the Task working directory), or use the Batch provided environment variable (https://learn.microsoft.com/azure/batch/batch-compute-node-environment-variables). Required.
command_line: str
constraints
The execution constraints that apply to this Task.
constraints: _models.BatchTaskConstraints | None
container_settings
The settings for the container under which the Task runs. If the Pool that will run this Task has containerConfiguration set, this must be set as well. If the Pool that will run this Task doesn't have containerConfiguration set, this must not be set. When this is specified, all directories recursively below the AZ_BATCH_NODE_ROOT_DIR (the root of Azure Batch directories on the node) are mapped into the container, all Task environment variables are mapped into the container, and the Task command line is executed in the container. Files produced in the container outside of AZ_BATCH_NODE_ROOT_DIR might not be reflected to the host disk, meaning that Batch file APIs will not be able to access those files.
container_settings: _models.BatchTaskContainerSettings | None
creation_time
The creation time of the Task. Required.
creation_time: datetime
depends_on
The Tasks that this Task depends on. This Task will not be scheduled until all Tasks that it depends on have completed successfully. If any of those Tasks fail and exhaust their retry counts, this Task will never be scheduled.
depends_on: _models.BatchTaskDependencies | None
display_name
A display name for the Task. The display name need not be unique and can contain any Unicode characters up to a maximum length of 1024.
display_name: str | None
environment_settings
A list of environment variable settings for the Task.
environment_settings: list['_models.EnvironmentSetting'] | None
etag
The ETag of the Task. This is an opaque string. You can use it to detect whether the Task has changed between requests. In particular, you can be pass the ETag when updating a Task to specify that your changes should take effect only if nobody else has modified the Task in the meantime. Required.
etag: str
execution_info
Information about the execution of the Task.
execution_info: _models.BatchTaskExecutionInfo | None
exit_conditions
How the Batch service should respond when the Task completes.
exit_conditions: _models.ExitConditions | None
id
A string that uniquely identifies the Task within the Job. The ID can contain any combination of alphanumeric characters including hyphens and underscores, and cannot contain more than 64 characters. Required.
id: str
last_modified
The last modified time of the Task. Required.
last_modified: datetime
multi_instance_settings
An object that indicates that the Task is a multi-instance Task, and contains information about how to run the multi-instance Task.
multi_instance_settings: _models.MultiInstanceSettings | None
node_info
Information about the Compute Node on which the Task ran.
node_info: _models.BatchNodeInfo | None
output_files
A list of files that the Batch service will upload from the Compute Node after running the command line. For multi-instance Tasks, the files will only be uploaded from the Compute Node on which the primary Task is executed.
output_files: list['_models.OutputFile'] | None
previous_state
The previous state of the Task. This property is not set if the Task is in its initial Active state. Known values are: "active", "preparing", "running", and "completed".
previous_state: str | _models.BatchTaskState | None
previous_state_transition_time
The time at which the Task entered its previous state. This property is not set if the Task is in its initial Active state.
previous_state_transition_time: datetime | None
required_slots
The number of scheduling slots that the Task requires to run. The default is 1. A Task can only be scheduled to run on a compute node if the node has enough free scheduling slots available. For multi-instance Tasks, this must be 1.
required_slots: int | None
resource_files
A list of files that the Batch service will download to the Compute Node before running the command line. For multi-instance Tasks, the resource files will only be downloaded to the Compute Node on which the primary Task is executed. There is a maximum size for the list of resource files. When the max size is exceeded, the request will fail and the response error code will be RequestEntityTooLarge. If this occurs, the collection of ResourceFiles must be reduced in size. This can be achieved using .zip files, Application Packages, or Docker Containers.
resource_files: list['_models.ResourceFile'] | None
state
"active", "preparing", "running", and "completed".
state: str | _models.BatchTaskState
state_transition_time
The time at which the Task entered its current state. Required.
state_transition_time: datetime
task_statistics
Resource usage statistics for the Task.
task_statistics: _models.BatchTaskStatistics | None
url
The URL of the Task. Required.
url: str
user_identity
The user identity under which the Task runs. If omitted, the Task runs as a non-administrative user unique to the Task.
user_identity: _models.UserIdentity | None