question

GunasekaranXKrishnan-5482 avatar image
0 Votes"
GunasekaranXKrishnan-5482 asked sadomovalex answered

Azure Scheduler job dependency

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

Hi @GunasekaranXKrishnan-5482 ,

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sadomovalex avatar image
0 Votes"
sadomovalex answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.