检测和处理 Batch 服务错误Detecting and handling Batch service errors

使用 REST 服务 API 时,务必检查是否有错误。It is important to remember to check for errors when working with a REST service API. 运行批处理作业时发生错误的情况并不少见。It isn't uncommon for errors to occur when running batch jobs.

常见错误Common errors

  • 网络故障 - 这些请求从未到达 Batch,或者 Batch 响应未及时到达客户端。Networking failures - these are requests that never reached Batch or the Batch response didn't reach the client in time.
  • 内部服务器错误 - 这些是标准 5xx 状态代码 HTTP 响应。Internal server errors - these are standard 5xx status code HTTP response.
  • 限制可能会导致错误,例如带有 Retry-after 标头的 429 或 503 状态代码 HTTP 响应。Throttling can cause errors such as 429 or 503 status code HTTP responses with the Retry-after header.
  • 4xx 错误,包括 AlreadyExists 和 InvalidOperation 等错误。4xx errors that include such errors as AlreadyExists and InvalidOperation. 这意味着资源未处于状态转换的正确状态。This means that the resource is not in the correct state for the state transition.

若要详细了解各种类型的错误代码和特定的错误代码,请参阅 Batch 状态和错误代码For detailed information about the various types of error codes and specific error codes, see Batch Status and Error Codes.

何时重试When to retry

如果出现错误,Batch API 会通知你。The Batch APIs will notify you if there is a failure. 这些 Batch API 都可以重试,并且都包含一个全局重试处理程序。They can all be retried, and they all include a global retry handler for that purpose. 最好使用此内置机制。It is best to use this built-in mechanism.

失败后,应等待一段时间(重试间隔为几秒钟),然后重试。After a failure, you should wait a bit (several seconds between retries) before retrying. 如果重试的次数过多或速度过快,重试处理程序会中止。If you retry too frequently or too quickly, the retry handler will throttle.

更多信息For more information

Batch API 和工具会链接到 API 参考信息。Batch APIs and tools links to API reference information. 例如,.NET API 包含 RetryPolicyProvider 类,应在其中指定所需的重试策略。The .NET API, for example, has a RetryPolicyProvider class where the required retry policy should be specified.

有关每个 API 及其默认重试策略的详细信息,请参阅 Batch 状态和错误代码For detailed information about each API and their default retry policies, read Batch Status and Error Codes.