Stop Azure WebJob from Azure WebSite

I recently had the need to toggle the status of an Azure WebJob from the WebSite in the same Azure App Service. I found a couple half-complete answers online, but I thought I'd put together this simple guide to have a complete example all in one place.

To accomplish this, we'll be using the kudu REST API for WebJobs.

(note: I also looked into toggling the WEBJOBS_STOPPED environment variable from the WebSite, however I was not able to verify that solution was going to work. I confirmed I was able to set the environment variable from the website, however the value did not update in the "Application Settings" section of the Azure Portal and I was concerned the WebJobs may read a separate environment variable than the WebSite [process scoped vs machine envar for example])

The first thing you'll need to do is download the PublishSettings file (aka "Publish Profile") associated with the App Service (you need the username/password from this file to satisfy the basic auth requirement to the kudu API)



In the "Web Deploy" publish profile section of this file, find the "userName" and "userPWD" values, we'll need these in the code linked below.


The full documentation describing all the various REST endpoints is available here. I have created a simple gist of how to authenticate using basic auth and call a few WebJob methods to start and stop services here: https://gist.github.com/aaronhoffman/212dd858ff5d4275369f5fde01d9fd5d


Hope this helps!
Aaron



Post a Comment

Popular posts from this blog

How to Turn Off Microsoft Arc Touch Mouse Scroll Sound Vibration

Hacker News Dataset October 2016

VirtualBox Right-Click Windows Taskbar On Mac