Azure batch immediately returning trigger to dependent task when resourcefilles are added

Parikh, Disham [ext] 30 Reputation points
2024-12-05T06:06:56.4766667+00:00

Hi,

I am using Azure batch task dependencies feature and facing one issue. I have one parent task which needs some data to process. I have configured ResourceFiles for my parent task so that it can download the files to process. I have dependent (child) task which should only trigger when parent task has completed it's process successfully (i.e., State = Success).

However, as ResourceFiles is configured for Parent task, it is immediately triggering the dependent (child) task once all files are downloaded via ResouceFiles from parent task. Which is not what I want. My dependent task should only run when parent task has executed the CommandLine and stored the Output file (which will be used in child task).

Code:

await CreateBatchPoolIfNotExists(BatchAccountResourceID, poolId);

List<CloudTask> tasks = new List<CloudTask>()
{
    new CloudTask("Parent","cmd /c [ffmpeg command]")
    {
        ResourceFiles = new List<ResourceFile>() 
        {
           ResourceFile.FromStorageContainerUrl("[CONTAINER_SAS_URL]", blobPrefix: "[BLOB_PATH_PREFIX]")
        },
        OutputFiles = new List<OutputFile>()
        {
            new OutputFile(
               filePattern: @"output_*.mp4",
               destination:
            new OutputFileDestination(new OutputFileBlobContainerDestination(
                       containerUrl: "[CONTAINER_SAS_URL]",
                       path: "[OUTPUT_BLOB_PATH]")),
               uploadOptions: new OutputFileUploadOptions(
               uploadCondition: OutputFileUploadCondition.TaskSuccess))
        }
    },
    new CloudTask("Child","cmd /c [ffmpeg command]")
    {
        DependsOn = TaskDependencies.OnId("Parent"),
        ResourceFiles = new List<ResourceFile>()
        {
           ResourceFile.FromStorageContainerUrl("[CONTAINER_SAS_URL]", blobPrefix: "[OUTPUT_BLOB_PATH_PREFIX]")
        },
        OutputFiles = new List<OutputFile>()
        {
            new OutputFile(
               filePattern: @"result_*.mp4",
               destination:
            new OutputFileDestination(new OutputFileBlobContainerDestination(
                       containerUrl: "[CONTAINER_SAS_URL]",
                       path: "[RESULT_BLOB_PATH]")),
               uploadOptions: new OutputFileUploadOptions(
               uploadCondition: OutputFileUploadCondition.TaskSuccess))
        }
    },
};

batchClient.JobOperations.AddTask(JobId, tasks);


Above code is executing successfully and able to create task and it's dependencies. However it end up triggering Child task without waiting for Parent to complete it's process completely (until Output is not created).

Please suggest the way forward.

Azure Batch
Azure Batch
An Azure service that provides cloud-scale job scheduling and compute management.
347 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,152 questions
{count} votes

Accepted answer
  1. anashetty 1,145 Reputation points Microsoft Vendor
    2024-12-12T08:43:30.7266667+00:00

    Hi Parikh, Disham [ext],

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others " Accept an answer on Microsoft Q&A, I'll repost your solution in case you'd like to "Accept " the answer.

    Issue:

    Azure batch immediately returning trigger to dependent task when resourcefulness are added.

    Solution:

    I was using same task name every time. so probably Microsoft is keeping some cached value inside a job and when I remove previous task and create a new Task with the name (Parent and Child), the state of the parent task was being fetched from the cache (assumption), and it was triggering the child task immediately.

    'Every time create a task with unique name to avoid being in this situation'

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    Thank you.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Annie Gharami 0 Reputation points Microsoft Employee
    2024-12-05T08:18:41.7533333+00:00

    Could you please verify if you have the following snippet in your code prior to creating the list of tasks for execution :

    // IMPORTANT: This is REQUIRED for using task dependencies.

    unboundJob.UsesTaskDependencies = true;

    await unboundJob.CommitAsync();

    If not, please add and then can you post if that works?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.