azure 批量更新作业的一个属性

问题描述 投票:0回答:1

我有一些 python 代码来创建作业,并添加一些任务。我希望该作业

OnAllTasksComplete.terminate_job
,但我无法在作业创建过程中设置它,因为它会在我有机会添加任务之前立即完成。所以我之后就这样做了。

这是我更新作业的 python 代码:

job = batch_service_client.job.update(job_id=job_id,job_update_parameter=batchmodels.JobUpdateParameter(on_all_tasks_complete=batchmodels.OnAllTasksComplete.terminate_job))

但是,根据文档,上面的代码片段不会仅更新此属性,而是重置所有其他属性(约束等)。有没有一种优雅的方法来做到这一点?

python azure azure-batch
1个回答
0
投票

您可以检索现有的作业属性,然后使用所需的属性修改作业,请参阅以下代码:-

from azure.batch import BatchServiceClient
from azure.batch.batch_auth import SharedKeyCredentials
from azure.batch import models as batchmodels

# Initialize Batch client
credentials = SharedKeyCredentials('siliconbatch67', '0xxxxxxxxxxxxABayxF3UQ==')
batch_service_client = BatchServiceClient(credentials=credentials, batch_url='https://siliconbatch67.australiaeast.batch.azure.com')

# Retrieve current job properties
job = batch_service_client.job.get(job_id='B2py', job_get_options=batchmodels.JobGetOptions(select='id'))

# Create pool info
pool_info = batchmodels.PoolInformation(pool_id='B2py')

# Modify the properties you need to change
job_update_parameter = batchmodels.JobUpdateParameter(
    pool_info=pool_info,
    on_all_tasks_complete=batchmodels.OnAllTasksComplete.terminate_job
)

# Update the job with the modified properties
batch_service_client.job.update(job_id='B2py', job_update_parameter=job_update_parameter)

输出:-

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.