BatchErrorException:指定的操作对于资源的当前状态无效

BatchErrorException: The specified operation is not valid for the current state of the resource

场景: 我有一个针对池的 azure batch 创建的工作。现在,我创建了另一个池,并希望将我的工作指向新创建的池。 我使用azure-batch SDK写了下面这段代码

import azure.batch.batch_service_client as batch
batch_service_client = batch.BatchServiceClient(credentials, batch_url = account_url)

job_id="LinuxTrainingJob"
pool_id="linux-e6a63ad4-9e52-4b9a-8b09-2a0249802981"

pool_info = batch.models.PoolInformation(pool_id=pool_id)
job_patch_param = batch.models.JobPatchParameter(pool_info=pool_info)
batch_service_client.job.patch(job_id, job_patch_param)

这给了我以下错误

BatchErrorException                       Traceback (most recent call last)
<ipython-input-104-ada32b24d6a0> in <module>
      2 pool_info = batch.models.PoolInformation(pool_id=pool_id)
      3 job_patch_param = batch.models.JobPatchParameter(pool_info=pool_info)
----> 4 batch_service_client.job.patch(job_id, job_patch_param)

~/anaconda3/lib/python3.8/site-packages/azure/batch/operations/job_operations.py in patch(self, job_id, job_patch_parameter, job_patch_options, custom_headers, raw, **operation_config)
    452 
    453         if response.status_code not in [200]:
--> 454             raise models.BatchErrorException(self._deserialize, response)
    455 
    456         if raw:

BatchErrorException: {'additional_properties': {}, 'lang': 'en-US', 'value': 'The specified operation is not valid for the current state of the resource.\nRequestId:46074112-9a99-4569-a078-30a7f4ad2b91\nTime:2020-10-06T17:52:43.6924378Z'}

凭据在上面设置并且工作正常,因为我能够使用相同的客户端创建池和作业。

环境详情

azure-batch==9.0.0
python 3.8.3
Ubuntu 18.04

要将作业分配给另一个池,您必须调用 disableJob API to drain currently running tasks from the Pool. Then you can call updateJob to assign a new poolId to run on. Once it is updated you can then call enableJob 以继续执行作业。