How can I keep my Azure WebJob running without "Always On" How can I keep my Azure WebJob running without "Always On" azure azure

How can I keep my Azure WebJob running without "Always On"


I've run into a similar problem. I have a website (shared mode) and an associated webjob (continuous type). Looking at webjob logs, I found that the job enters stopped state after about 15 min. of inactivity and stops reacting to trigger messages. It seems contradictory to the concept of continuous job concept but, apparently, to get it running truly continuously you have to subscribe to a paid website. You get what you pay for...

That said, my website needs to be used only about every few days and running in a shared mode makes perfect sense. I don't mind that the site needs a bit extra time to get started - as long as it restarts automatically. The problem with the webjob is that once stopped it won't restart by itself. So, my goal was to restart it with the website.

I have noticed that a mere look at the webjob from Azure Management Portal starts it. Following this line of thinking, I have found that fetching webjob properties is enough to switch it to the running state. The only trick is how to fetch the properties programmatically, so that restarting the website will also restart the webjob.

Because the call to fetch webjob properties must be authenticated, the first step is to go to Azure Management Portal and download the website publishing profile. In the publishing profile you can find the authentication credentials: username (usually $<website_name>) and userPWD (hash of the password). Copy them down.

Here is a function that will get webjob properties and wake it up (if not yet running):

class Program{    static void Main(string[] args)    {        string websiteName = "<website_name>";        string webjobName = "<webjob_name>";        string userName = "<from_publishing_profile>";        string userPWD = "<from_publishing_profile>";        string webjobUrl = string.Format("https://{0}.scm.azurewebsites.net/api/continuouswebjobs/{1}", websiteName, webjobName);        var result = GetWebjobState(webjobUrl, userName, userPWD);        Console.WriteLine(result);        Console.ReadKey(true);    }    private static JObject GetWebjobState(string webjobUrl, string userName, string userPWD)    {        HttpClient client = new HttpClient();        string auth = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userName + ':' + userPWD));        client.DefaultRequestHeaders.Add("authorization", auth);        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));        var data = client.GetStringAsync(webjobUrl).Result;        var result = JsonConvert.DeserializeObject(data) as JObject;        return result;    }}

You can use a similar function to get all webjobs in your website (use endpoint https://<website_name>.scm.azurewebsites.net/api/webjobs). You may also look at the returned JObject to verify the actual state of the webjob and other properties.


If you want the WebJob to not stop you need to make sure your scm site is alive.

So the keep-alive requests should go to https://sitename.scm.azurewebsites.net and these requests need to be authenticated (basic auth using your deployment credentials).