question

fhtino avatar image
0 Votes"
fhtino asked SwathiDhanwada-MSFT commented

How to set a runbook / job timeout?

Hi, I have created a runbook and successfully scheduled it to run every day. Now, I would like to set a timeout on the runbook or scheduled job to kill my job in case it is still running after x minutes. Is it possible?
I know that I could do something inside the powershell script but I would prefer an external system that kill my job if its running time exceeded a value.


azure-automation
· 1
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.

@fhtino Apologies for late response. I am looking into it and will provide a response soon.

0 Votes 0 ·

1 Answer

SwathiDhanwada-MSFT avatar image
0 Votes"
SwathiDhanwada-MSFT answered SwathiDhanwada-MSFT commented

@fhtino I understand you want to terminate scheduled jobs if it exceeds specified time. You can create PowerShell Script which retrieves the job information. For this, you can use Get-AzAutomationJob. Retrieve the difference between current time and start time and compare it to specified time. If it exceeds, then you can stop the job using Stop-AzAutomationJob or Suspend-AzAutomationJob.




· 4
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.

Hi @SwathiDhanwada-MSFT if I understand correctly you are suggesting to create 2 job: the former doing the real activities and the latter monitoring the former and killing it if required. Let me say that this sound a bit tricky and even costly. I have to pay for 2 jobs.
I was looking for something like Windows Scheduler timeout or linux crontab + timout command. So, something natively managed by Azure Automation.
If this feature is not available, can you pass the idea to the team or let me know how to suggest it. Thanks

0 Votes 0 ·

@fhtino Based on the information that you are looking native to Azure Automation. I assume you are using Azure sandboxes to run your runbooks. To share resources among all runbooks in the cloud, Azure uses a concept called fair share. Using fair share, Azure temporarily unloads or stops any job that has run for more than three hours. Jobs for PowerShell runbooks and Python runbooks are stopped and not restarted, and the job status becomes Stopped.

If any job is taking time to run more than three hours, the job fails because it reached the fair share limit three times and started from the same checkpoint or from the start of the runbook each time. For more information, you can refer this document.

For any product feedback, I would recommend you to navigate here and share your feedback or suggestions directly with the responsible Azure feature team and clicking the vote button of your suggestion to raise visibility and priority on it.


0 Votes 0 ·