Azure Scheduler job dependency

Gunasekaran X Krishnan 1 Reputation point
2021-09-13T21:06:04.927+00:00

Hello,

We have a recurring job scheduled using azure automation account for every 2Hrs. We don't want multiple jobs run at sametime, basically if a job is running, the next one should not start until the running one is complete even after the 2Hr window.

Is it possible to add dependency in the schedule to have the job start only if the current job is completed.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,192 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 103.8K Reputation points MVP
    2021-09-13T21:22:30.633+00:00

    Hi @Gunasekaran X Krishnan ,

    this should be possible.

    With the cmdlet Get-AzAutomationJob it should be possible to query the Azure Automation jobs. Based on the result of the job list and status of the jobs in the lists check if a job of the runbook is still running.

    Just a draft of the runbook:

    • Schedule the runbook every 2 hours
    • Check if another job instance of the runbook is still running
    • If "yes" = End/exit
    • if "no" = go further and do the magic
    • Check at the end if the 2 hours schedule is breached (runbook runs longer than 2 hours)
    • if "yes" = start another job instance ( Start-AzAutomationRunbook )
    • if "no" = end (wait for the next schedule interval)

    This should be doable with PowerShell.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  2. sadomovalex 3,631 Reputation points
    2021-09-16T15:14:09.57+00:00

    just as idea: is it possible to do the same task using Azure web job? They also can run by scheduler (set via cron expression) and in this case nothing should be done for ensuring that only one instance runs at a time - this is by design for web jobs. They use lock files to prevent 2nd instance of the same web job to start until 1st instance will finish.

    0 comments No comments