• Getting notified when your Azure triggered WebJobs completes

    31 Mar 2014

    Microsoft Azure WebJobs are awesome, and now a little bit more... I'm going to show you how you can setup a notification whenever your triggered (on-demand or scheduled) WebJobs completes.

    The notification part is done by integration between Azure and Zapier which provides many different notification types such as: email, phone call, SMS, Facebook post and more, for this post I'll use a phone call but it is very easy to use any of them.

    NOTE: In a previous post I explained about Zapier and how you can have a notification when your Azure Website deployment completes, this is very similar only with a triggered WebJob.

    Let's do it:

    Prerequisites

    • An Azure Website with at least 1 triggered (on-demand or scheduled) WebJob (although you can add it later).

    • Sign up to Zapier

    • Have both the Zapier and Azure portal open

    Steps

    • Go to Zapier and create a new zap (Make a Zap!).

    • For the trigger service select Azure Web Sites.

    • For the trigger select New Triggered WebJob Run.

    • For the action, we'll select Phone and Call Phone for this sample but any can be selected.

    • Click Continue

    • We need to connect to our Azure Web Site hosting our triggered WebJob, for this we need one piece of information from the Azure portal.

    This is the tricky part:

    • If your website has continuous deployment setup --> in the Azure portal go to your website, click on the CONFIGURE tab and under the git section copy the url which is under the DEPLOYMENT TRIGGER URL.

    • If you don't have continuous deployment, you can author this url yourself, it is: https://{userName}:{password}@{siteName}.scm.azurewebsites.net/deploy where you get the {userName} and {password} from your site's publishing profile.

    • Go back to the Zapier site and paste this url to the Deployment URL textbox, enter a name for this website account and click continue.

    • Now create your phone account by providing the phone number and verifying it.

    • At this point you can filter when you actually want to initiate the action, for example only when the WebJob run fails or only for a specific WebJob (by name), for now we keep this empty as we want to be notified on all WebJobs runs, click continue.

    • Next you specify the content of the message, it can be static and dynamic using the WebJob run result.

    • For example we'll use: Hello the WebJob named {{job_name}} has completed with status {{status}} and took {{duration}}, on the right you can use the "Insert fields" button to add other interesting dynamic fields.

    • You can even choose the voice of the caller (Man/Woman), I'll let you pick this one.

    • Continue

    • Test this Zap lets you test your zap by getting previous WebJob runs and doing the selected action on them, click the button and then you can skip the step or test your Zap.

    • Name and turn this Zap on

    • Now go to your Azure portal, run your WebJob, wait for it to complete and wait for the call :)

    Get more help about Windows Azure Web Sites on Zapier.

    Read more...


  • Request for a specific Azure website instance

    In Windows Azure Websites you have the ability to scale your site by adding more instances to it where each instance is running on a different VM.

    When you have more than one instance a request made to your site can go to any of them using a load-balancer that will decide which instance to route the request to based on how busy each instance is at the time.

    One feature of this load-balancer is that once a request from your browser is made to the site, it will add a "cookie" to it (with the response) containing the specific instance id that will make the next request from this browser go to the same instance.

    We can use this feature to send a request to a specific instance of our site.

    The name of the cookie we're going to use is: ARRAffinity

    Code

        private static async Task<HttpResponseMessage> GetFromInstance(Uri url, string instanceId)
        {
            var cookieContainer = new CookieContainer();
            using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
            {
                using (var httpClient = new HttpClient(handler))
                {
                    cookieContainer.Add(url, new Cookie("ARRAffinity", instanceId));
                    return await httpClient.GetAsync(url);
                }
            }
        }
    

    The problem that we have now is getting this instance id, currently there is no API that will give us all the current instance ids, but a specific site can find out it's own instance id by looking at the environment variable called: WEBSITE_INSTANCE_ID.

    So one application for this is that we can create a WebJob that is able to call the Website it is hosted on.

    WebJob Code

        private static void Main(string[] args)
        {
            string instanceId = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
            string siteName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME");
            var url = new Uri("http://" + siteName + ".azurewebsites.net/");
            var response = GetFromInstance(url, instanceId).Result;
            Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        }
    

    Hope this helps.

    Read more...


  • Blog.Amit Apple now powered by Sandra.Snow

    24 Jan 2014

    I've been wanting to self-host my blog on my own Windows Azure Website for some time now and I've found the perfect solution (for me) to do that in Sandra.Snow.

    Sandra.Snow is a Jekyll inspired static site generation tool that can be run locally, as a CAAS(Compiler as a Service) or setup with Azure to build your site when your repository changes. It is built on top of NancyFX.

    It allows me to store all my posts as markdown files on a git repository on GitHub, and having my Website hooked up to that repository so whenever I push a new change/post my site is automatically redeployed and updated.

    Read more...