Blog Post

Azure PaaS Blog
3 MIN READ

How to create multiple tasks under a job in Job Scheduler

lakshmijakka's avatar
lakshmijakka
Icon for Microsoft rankMicrosoft
Dec 27, 2024

In this article you will see detailed procedure of how to create jobs with tasks in a Job scheduler.

You can follow below doc on how to schedule jobs in a job scheduler.

Schedule Batch jobs for efficiency - Azure Batch | Microsoft Learn

While creating a job scheduler, you will see Job Specification section. In this section, you would need to update Job configuration task to add jobs.

You will further see below settings.

 

To add tasks to the Job in the job scheduler, you would need to add Job manager task. A job manager task contains the information that is necessary to create the required tasks for a job. A job manager task is required for jobs that are created by a  job schedule, because it is the only way to define the tasks before the job is instantiated.

 

You can further change other settings if required. Once the job scheduler is created, you will see a job with name job-1 is created under the job scheduler.

 

Inside, job-1 you can see a task is created. This task is nothing but the job manager task.

 

With this you will be able to create only one job with only one task (job manager task) in a single job scheduler.

In some scenarios, you may need to add more tasks to a job in a Job scheduler. For this scenario, you can follow the below approach.

To create more tasks under the job that job scheduler generates, it is expected for user to write some command line calling Task-Add API in the job manager task like below.

/bin/sh -c 'az batch task create --job-id $(printenv AZ_BATCH_JOB_ID) --account-endpoint "https://batchname.xxx.batch.azure.com" --account-key "ACCOUNT_KEY" --account-name "BATCH_ACCOUNT_NAME" --task-id "TASK_ID" --command-line "TASK_COMMAND_LINE"'

Example:

/bin/sh -c 'az batch task create --job-id $(printenv AZ_BATCH_JOB_ID) --account-endpoint "https://batchtest.westeurope.batch.azure.com" --account-key " YdFUnnV65NlcfzXf+T48YCeGo/Z2ZMqIyiQxRrgMxxxxxxxxxxx” --account-name "batchtest" --task-id "task2" --command-line "/bin/sh -c echo ‘Hello' "'

Also while creating Job scheduler, make sure to define the following properties.

1. Kill Job on completion:

This property is true by default. If true, when a job manager task is completed, the Batch service marks the job as completed. If false, the completion of the Job Manager task does not affect the job status. In this case, the user needs to terminate the job explicitly. This is to make sure that if the Job Manager creates a set of tasks but then takes no further role in their execution.

 

 

2. Specify When all tasks complete to TerminateJob to explicitly.

With above, you will achieve two tasks under a job in job scheduler. One is job manager task(task1) and the other is the task(task2) created from command line of job manager task.

 

Note : 

A job scheduler can have at most one active job under it at any given time. So, if it is time to create a new job under a job schedule, but the previous job is still running, the Batch service will not create the new job until the previous job finishes. If the previous job does not finish within the startWindow period of the new recurrence interval, then no new job will be scheduled for that interval.

Published Dec 27, 2024
Version 1.0
No CommentsBe the first to comment