Azure Webjobs deployment

Intro to Azure Webjobs covers what it is and why you should actually start using it for your job like batch processing, cpu intensive task etc. In this blog post I will just hit the surface of azure webjobs. So no big deal, this will be an easy to follow step by step guideline so that you can see how easy to get started with azure webjobs.

But before I start, there are few concepts/terms I need you to be aware of. Webjobs could be invoked in two different ways.

  1. Triggered jobs – When you want to do some task based on some event trigger or want to run on a schedule time those jobs are triggered jobs.
  2. Continuous jobs – Continuous jobs basically run a while loop.

Redeploy, Recycle any time :

Azure Webjobs handle the redeployment process based on job types. For triggered jobs redeployment will not affect instantly, that means the currently running WebJob will not affected by it. The next run will use the new binaries. On its contrary, for continuous job redeployment will abort the current running process and restart with the new binaries. Now you might be wondering how it is actually possible to modify or delete binaries  in webjobs while its already in use. Well, thats an interesting question. Under the hood, WebJob copies the binaries to a temporary directory before it actually start running. That is how it always ensure that your file never gets locked down in the process of redeployment.

Enough talk. Let me jump into our first simple demo to see how things actually wired up in webjobs.

I have just created a simple console application with only one line of code that prints the sentence Hello Webjobs! in the console and then I fly to the debug folder under bin directory which shows something like this –

AzureWebjobs_02_01

Now, my target is to zip the entire contents of this folder. This is the zip file that I am going to upload to azure webjobs. In my case the zip contains an executable file named HelloWebjobs which prints a statement in the console.

Then I head over to azure portal and click AzureWebjobs_02_02 from the left side panel which will show me a list of web apps running on my account. I click the web app(in my case its called webapplication39758) with which I want to integrate my webjob task. Then I scroll down the Settings plate unless I found the WebJobs option. Clicking this will open up a new blade. Click the AzureWebjobs_02_02+ button and this will open up a new blade.

AzureWebjobs_02_03

I provide a Name for my webjob , also configure the way it should run (i.e. On Demand or Continuous) and finally upload the zip file that I have created little earlier. Once I am done with all these settings I click the Create button to complete the process.

Once the webjob gets created successfully it will showed up in the WebJobs blade.

AzureWebjobs_02_04

Since it is a On Demand type job so I need to manually run it from the portal. I can do so by right clicking on the job and from the context menu I select Run.

AzureWebjobs_02_05

My notification icon got green saying the job ran successfully. I can always check the log file for further investigation. When I clicked the log  url it shows me an overview that states which executable file it tried to run and list of recent job status.  I can see if any of my webjob ever failed by having a look on the status segment.

AzureWebjobs_02_07

If for any reason I need to dig deeper I can do that easily. I can click any of the job listed here on the above dashboard and this will show me in depth information.

AzureWebjobs_02_06

This is pretty much everything!

Before wrapping this tutorial I want to emphasize one last thing. Be careful while creating the zip. While your zip can contain one to many files, you need to make sure it has a entry point which will initiate the webjob task. Recall from Intro to Azure Webjobs you can write scripts on different language. Which of your script/executable file will be considered as your entry point shall be automatically detected by the following logic

  • First look for a file called run.{supported extension} (first one found wins).
  • If not found look for any file with a supported extension.
  • If not found, this is not a runnable WebJob

Wrapping Up:

In azure you can setup your webjobs in varies way, this is just one of the process that I have shown here. My simple console app only print a sentence, but that is only for demonstration purpose. You should instead run your CPU intensive work. If you ever come across in a situation where you want some other type of file to be executed which is currently not supported in webjobs then for such situation the work around that you can follow is to create a run.cmd file and create your executor command there (powershell -Command run.ps).

Advertisements

3 thoughts on “Azure Webjobs deployment

  1. Pingback: Webjob deployment experience with Visual Studio | LearnWithShahriar

  2. Pingback: Azure Webjob ebook is on the way ! | LearnWithShahriar

  3. Pingback: Azure WebJob SDK Intro | LearnWithShahriar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s