locked
How to stop a web-job? RRS feed

  • Question

  • Hi,

    I can schedule or 'run at once' a webjob. How to stop nicely a web-job that is currently running or to prevent it to run (when already scheduled, but without changing the schedule)?

    Tuesday, August 25, 2015 5:56 AM

Answers

  • Hi,

    The best option we have found is to use KUDU api for getting list of processes, and then kill the desired webjob process. With Kudu API you can use below powershell script

    $username = $website.PublishingUsername
        $password = $website.PublishingPassword
        $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
        $ps = Invoke-RestMethod -Uri "$apiBaseUrl/processes" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET    
        $id = $($ps | where {$_.name -eq $jobname} ).id
        Invoke-RestMethod -Uri "$apiBaseUrl/processes/$id" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method DELETE    
        write-host "killed process $id"
    

    Thanks

    Abhishek

    Tuesday, August 25, 2015 7:16 AM
  • Hi Thomas

    Have a look at this blog from Scott Hanselman on Azure Web Jobs it provides loads of great tips/best practices http://www.hanselman.com/blog/IntroducingWindowsAzureWebJobs.aspx

    And this set of example on Powershell command and Web Jobs by Nick Trogh http://blogs.msdn.com/b/nicktrog/archive/2014/01/22/running-powershell-web-jobs-on-azure-websites.aspx

    If you want to stop a started webjob - Kudu - https://github.com/projectkudu/kudu/wiki/Process-Threads-list-and-minidump-gcdump-diagsession is the best way of doing this as Abhishek suggested.

    In regards to killing it from the portal you can do as follows

    1. Kill a running webjob, go to {sitename}.scm.azurewebsites.net, and the use the Process Explorer to view/kill relevant processes.

    Azure Websites customers can now monitor and manage website processes through Process Explorer. Process Explorer is also the name of a Sysinternals tool and provides much of the same functionality. The Cloud version allows you to enumerate the various Azure-hosted websites and drill down into each process to determine if specific handles or modules might be causing issues with performance or other website degrading activity. And, just as you can in the Sysinternals tool, you can kill specific processes that might be causing harm.

    Process Explorer capability for Azure Websites is free for all paying customers. Check out Azure Websites here: Websites and Apps

    Hope this helps if it does please mark it as an answer or helpful post.

     






    Sunday, September 6, 2015 7:56 PM

All replies

  • Hi,

    The best option we have found is to use KUDU api for getting list of processes, and then kill the desired webjob process. With Kudu API you can use below powershell script

    $username = $website.PublishingUsername
        $password = $website.PublishingPassword
        $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
        $ps = Invoke-RestMethod -Uri "$apiBaseUrl/processes" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET    
        $id = $($ps | where {$_.name -eq $jobname} ).id
        Invoke-RestMethod -Uri "$apiBaseUrl/processes/$id" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method DELETE    
        write-host "killed process $id"
    

    Thanks

    Abhishek

    Tuesday, August 25, 2015 7:16 AM
  • Thanks, but that's too much :-)

    I would like to do it directly from the portal...
    Tuesday, August 25, 2015 7:38 AM
  • Hi Thomas

    Have a look at this blog from Scott Hanselman on Azure Web Jobs it provides loads of great tips/best practices http://www.hanselman.com/blog/IntroducingWindowsAzureWebJobs.aspx

    And this set of example on Powershell command and Web Jobs by Nick Trogh http://blogs.msdn.com/b/nicktrog/archive/2014/01/22/running-powershell-web-jobs-on-azure-websites.aspx

    If you want to stop a started webjob - Kudu - https://github.com/projectkudu/kudu/wiki/Process-Threads-list-and-minidump-gcdump-diagsession is the best way of doing this as Abhishek suggested.

    In regards to killing it from the portal you can do as follows

    1. Kill a running webjob, go to {sitename}.scm.azurewebsites.net, and the use the Process Explorer to view/kill relevant processes.

    Azure Websites customers can now monitor and manage website processes through Process Explorer. Process Explorer is also the name of a Sysinternals tool and provides much of the same functionality. The Cloud version allows you to enumerate the various Azure-hosted websites and drill down into each process to determine if specific handles or modules might be causing issues with performance or other website degrading activity. And, just as you can in the Sysinternals tool, you can kill specific processes that might be causing harm.

    Process Explorer capability for Azure Websites is free for all paying customers. Check out Azure Websites here: Websites and Apps

    Hope this helps if it does please mark it as an answer or helpful post.

     






    Sunday, September 6, 2015 7:56 PM
  • Here are the steps to Kill a Web Jobs in Azure,

    Kudu is the Tool in Azure to check Background process.

    Kudu URL Format: yourWebSite.scm.azurewebsites.net

    Sample URL: google.scm.azurewebsites.net

    Login to KUDU web site portal 

    In Kudu - Select the Process option Menu option

    Select on Web Jobs – that suppose to be killed [Properties]

    Use Kill Option below, drag down to see the "KILL" button

    Click on button "KILL", Killing of Process – Indicated [Red Color]

    Once Process Killed Successfully, it will not be displayed.

    How ever the webjobs will be in Failed state.

    http://stackoverflow.com/questions/26636995/azure-stop-a-triggered-web-job/39411498#39411498

    Friday, September 9, 2016 12:22 PM