Azure Automation - Jobs stuck in running and stopped after 3 hours

Ajay Kumar 1 Reputation point
2020-10-31T20:35:38.31+00:00

Hi Team,

I have scheduled an automation job to suspend/delete users based on their last sign-in. I am fetching last Sign-ins from Azure Log analytics.

I am getting below error intermittently. Some times it completes within 32 mins without any issue and some time it stopped with below message.
Error -
"The job has been stopped because it reached the fair share limit of job execution more than 3 hours. For long-running jobs, it's recommended to use a Hybrid Runbook Worker. Hybrid Runbook Workers don't have a limitation on how long a runbook can execute. Refer https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution#fair-share for more details."

Below are the few Azure commands i am using -

  1. Connect-AzureAD
  2. Connect-azurermaccount
  3. Get-AzureADUser
  4. Create users batch of 2000
  5. Invoke-AzureRmOperationalInsightsQuery -WorkspaceId "WorkspaceID" -Query $query -ErrorAction Stop -wait 360

The job usually connect with Azure and AzureRM but it stuck while fetching the last sign-in logs from Azure log analytics.

What could be the issue? Is it required to use Hybrid Runbook Workers here? Any clue?

More Information -

  1. Azure Automation Account - Region North EU
  2. Azure Log Analytics - Region West EU

Thanks
Ajay

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

5 answers

Sort by: Most helpful
  1. Andreas Baumgarten 111.1K Reputation points MVP
    2020-10-31T22:53:51.56+00:00

    I would recommend to migrate from AzureRM to Az.
    AzureRM is outdated and is replaced by the new Az module.
    https://learn.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-5.0.0

    Maybe this will help.

    The automation job is a new one? Or it was running fine earlier days and now it's causing issues?

    ----------

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

    Regards
    Andreas Baumgarten


  2. SwathiDhanwada-MSFT 18,771 Reputation points
    2020-11-05T08:23:33.717+00:00

    @Ajay Kumar As mentioned by @Andreas Baumgarten , it is recommended to migrate from AzureRM to Az modules.

    To your questions related to the error, please note that maximum run time allowed for runbook using Azure Sandbox is 3 hours. Seems the runtime has exceeded in your case. Hence , you were prompted with the mentioned error ""The job has been stopped because it reached the fair share limit of job execution more than 3 hours. For long-running jobs, it's recommended to use a Hybrid Runbook Worker. Hybrid Runbook Workers don't have a limitation on how long a runbook can execute. Refer https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution#fair-share for more details."

    37626-image.png

    Kindly note if a query takes longer than the specified timeout (or default timeout, if unspecificed), it will fail with an status code of 504 Gateway Timeout which you have noticed when executing Invoke-AzureRmOperationalInsightsQuery command.

    To check the execution time of your PowerShell Script, I would suggest you to check this third party article which helps to measure time taken to execute the script. Based on your execution time, you can choose to improvise your script or select hybrid runbook worker for execution.

    0 comments No comments

  3. sadomovalex 3,631 Reputation points
    2020-11-06T15:15:46.147+00:00

    did you try to run the same code locally (not from Azure)? Does it also stuck in this case?


  4. SwathiDhanwada-MSFT 18,771 Reputation points
    2020-11-07T04:33:54.55+00:00

    @Ajay Kumar Kindly note authentication using AAD inside Azure Runbooks using Azure Sandbox is not supported. The only options are using an Hybrid worker or using Azure Functions.

    38078-image.png

    Reference Links:


  5. Ajay Kumar 1 Reputation point
    2020-11-12T15:55:05.49+00:00

    Hi @SwathiDhanwada-MSFT , Currently i am working on AzureRM to Az migration and getting below warning with Connect-AzAccount. Can you please share your thoughts on this? Although i get the results.

    Warning -
    TenantId 'XXXXX' contains more than one active subscription. First one will be selected for further use. To select another subscription, use Set-AzContext.

    I can see in the below link that there is an issue with Az module > version1.9.5. I am using version 2.1.2.

    Link -
    https://github.com/Azure/azure-powershell/issues/13337


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.