任务完成事件Task complete event

无论退出代码如何,任务完成后都会发出此事件。This event is emitted once a task is completed, regardless of the exit code. 此事件可用于确定任务的持续时间、运行位置以及是否重试过。This event can be used to determine the duration of a task, where the task ran, and whether it was retried.

以下示例显示了任务完成事件的正文。The following example shows the body of a task complete event.

{
    "jobId": "myJob",
    "id": "myTask",
    "taskType": "User",
    "systemTaskVersion": 0,
    "requiredSlots": 1,
    "nodeInfo": {
        "poolId": "pool-001",
        "nodeId": "tvm-257509324_1-20160908t162728z"
    },
    "multiInstanceSettings": {
        "numberOfInstances": 1
    },
    "constraints": {
        "maxTaskRetryCount": 2
    },
    "executionInfo": {
        "startTime": "2016-09-08T16:32:23.799Z",
        "endTime": "2016-09-08T16:34:00.666Z",
        "exitCode": 0,
        "retryCount": 0,
        "requeueCount": 0
    }
}
元素名称Element name 类型Type 说明Notes
jobId StringString 包含任务的作业的 ID。The ID of the job containing the task.
id StringString 任务的 ID。The ID of the task.
taskType StringString 任务的类型。The type of the task. 它可以是“JobManager”(指示它是作业管理器任务),也可以是“User”(指示它并非作业管理器任务)。This can either be 'JobManager' indicating it is a job manager task or 'User' indicating it is not a job manager task. 对于作业准备任务、作业释放任务或开始任务,不会发出此事件。This event is not emitted for job preparation tasks, job release tasks or start tasks.
systemTaskVersion Int32Int32 这是任务上的内部重试计数器。This is the internal retry counter on a task. 批处理服务可能会在内部重试任务来解决暂时性问题。Internally the Batch service can retry a task to account for transient issues. 这些问题可能包括内部计划错误或尝试恢复处于错误状态的计算节点。These issues can include internal scheduling errors or attempts to recover from compute nodes in a bad state.
requiredSlots Int32Int32 运行任务所需的槽。The required slots to run the task.
nodeInfo 复杂类型Complex Type 包含有关运行任务的计算节点的信息。Contains information about the compute node on which the task ran.
multiInstanceSettings 复杂类型Complex Type 指定任务是需要多个计算节点的多实例任务。Specifies that the task is a Multi-Instance Task requiring multiple compute nodes. 有关详细信息,请参阅 multiInstanceSettingsSee multiInstanceSettings for details.
constraints 复杂类型Complex Type 应用到此任务的执行约束。The execution constraints that apply to this task.
executionInfo 复杂类型Complex Type 包含有关任务执行的信息。Contains information about the execution of the task.

nodeInfonodeInfo

元素名称Element name 类型Type 说明Notes
poolId StringString 运行任务的池的 ID。The ID of the pool on which the task ran.
nodeId 字符串String 运行任务的节点的 ID。The ID of the node on which the task ran.

multiInstanceSettingsmultiInstanceSettings

元素名称Element name 类型Type 说明Notes
numberOfInstances Int32Int32 任务所需的计算节点数。The number of compute nodes required by the task.

constraintsconstraints

元素名称Element name 类型Type 说明Notes
maxTaskRetryCount Int32Int32 可以重试任务的最大次数。The maximum number of times the task may be retried. 批处理服务在其退出代码非零时重试任务。The Batch service retries a task if its exit code is nonzero.

请注意,此值专门用于控制重试的次数。Note that this value specifically controls the number of retries. 批处理服务将尝试任务一次,然后重试,直至达到此上限为止。The Batch service will try the task once, and may then retry up to this limit. 例如,如果最大重试计数为 3,则批处理任务最多尝试任务 4 次(一次是初始尝试,其余 3 次是重试)。For example, if the maximum retry count is 3, Batch tries a task up to 4 times (one initial try and 3 retries).

如果最大重试计数为 0,则批处理服务不会重试任务。If the maximum retry count is 0, the Batch service does not retry tasks.

如果最大重试计数为 -1,则批处理服务会无限制地重试任务。If the maximum retry count is -1, the Batch service retries tasks without limit.

默认值为 0(不重试)。The default value is 0 (no retries).

executionInfoexecutionInfo

元素名称Element name 类型Type 说明Notes
startTime DateTimeDateTime 任务开始运行的时间。The time at which the task started running. “Running”对应于 正在运行 状态,因此如果任务指定资源文件或应用程序包,则开始时间反映了任务开始下载或部署这些内容的时间。'Running' corresponds to the running state, so if the task specifies resource files or application packages, then the start time reflects the time at which the task started downloading or deploying these. 如果任务已重启或重试,该时间是任务开始运行的最近时间。If the task has been restarted or retried, this is the most recent time at which the task started running.
endTime DateTimeDateTime 任务完成的时间。The time at which the task completed.
exitCode Int32Int32 任务的退出代码。The exit code of the task.
retryCount Int32Int32 批处理服务重试任务的次数。The number of times the task has been retried by the Batch service. 如果任务使用非零退出代码退出,该任务会重试,直至达到指定的 MaxTaskRetryCount。The task is retried if it exits with a nonzero exit code, up to the specified MaxTaskRetryCount.
requeueCount Int32Int32 批处理服务因用户请求而对任务进行重新排队的次数。The number of times the task has been requeued by the Batch service as the result of a user request.

当用户从池中删除节点(通过调整池的大小或缩小池)或作业已禁用时,用户可以指定节点上运行的任务重新排队等待执行。When the user removes nodes from a pool (by resizing or shrinking the pool) or when the job is being disabled, the user can specify that running tasks on the nodes be requeued for execution. 此计数跟踪由于这些原因而重新排队任务的次数。This count tracks how many times the task has been requeued for these reasons.