简体   繁体   中英

Unable to add Task To Azure Batch Model

I am trying to create Azure Batch Job with Task which uses output_files as a Task Parameter

tasks = list()
command_task = (r"cmd /c dir")

# Not providing actual property value for security purpose
containerName = r'ContainerName'
azureStorageAccountName = r'AccountName'
azureStorageAccountKey = r'AccountKey'

sas_Token = generate_account_sas(account_name=azureStorageAccountName, account_key=azureStorageAccountKey, resource_types=ResourceTypes(object=True), permission=AccountSasPermissions(read=True, write=True), expiry=datetime.datetime.utcnow() + timedelta(hours=1))

url = f"https://{azureStorageAccountName}.blob.core.windows.net/{containerName}?{sas_Token}"

output_file = batchmodels.OutputFile(
        file_pattern=r"..\std*.txt",
        destination=batchmodels.OutputFileDestination(
            container=batchmodels.OutputFileBlobContainerDestination(container_url=url),
            path="abc"),
        upload_options='taskCompletion')

tasks.append(batchmodels.TaskAddParameter(id='Task1', display_name='Task1', command_line=command_task, user_identity=user, output_files=[output_file]))

batch_service_client.task.add_collection(job_id, tasks)

On Deugging this code I am getting exception as在此处输入图像描述

But on removing the output_files parameter, everything works fine and Job is created with task.

I missed out upload_options object while creating OutputFile object:

output_file = batchmodels.OutputFile(
        file_pattern=r"..\std*.txt",
        destination=batchmodels.OutputFileDestination(
            container=batchmodels.OutputFileBlobContainerDestination(container_url=url),
            path="abc"),
        upload_options=batchmodels.OutputFileUploadOptions('taskCompletion'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM