Deploy Windows Azure WebJobs

Original author: Amit Apple
  • Transfer
Windows Azure WebJobs is a new feature of Windows Azure Web Sites, you can read more about it here .

Although you can easily add a new WebJob using the Windows Azure management portal, you might want to deploy WebJob in other ways - ftp / git / WebDeploy. In this post, I will show how WebJobs are stored in your Azure WebSites and how you can deploy a new WebJob.


Where are WebJobs stored?


WebJobs are saved in the following directory of your site:
site \ wwwroot \ App_Data \ jobs \ {job type} \ {job name}

Where {job type} can be either continuous for constantly running WebJob, or triggered for those that start on a trigger (on demand or on a schedule).
{job name} is the name of your WebJobs.

Thus, a constantly running WebJob named myjob will be located in
site \ wwwroot \ App_Data \ jobs \ continuous \ myjob

What should be inside the directory with WebJob?


The WebJob directory can contain from one to as many files as you need, but at least it should contain a script that starts the WebJob process. At the moment, this may be:
  1. Batch file (.exe / .cmd / .bat)
  2. Bash (.sh)
  3. JavaScript (.js for node.js)
  4. PHP (.php)
  5. Python (.py)


Scripts are run automatically by the following logic:
  1. First, a file named run is searched. {Supported extension} (the first one found wins)
  2. If it is not found, any file with the supported extension is searched
  3. If not found, and it is not WebJob launchable


Note: if you have some other script execution engine that you want to use
that is not supported at the moment, you can always create a run.cmd file and write a command to execute there (for example, powershell -Command run.ps )


WebJob Deployment


So, thanks to this information, you know how to create a constantly working WebJob called myjob, and all that remains to be done is to put the binary files in the correct directory.

One way to do this is to connect to your site via FTP, create a directory with the correct name and copy binary files (containing at least one supported script file) there. Then WebJob will be detected automatically and will immediately start executing.

WebSite + WebJobs Deployment


To deploy a site with WebJobs, all you have to do is make sure you deploy your WebJob to the right place. For an example, take a look at the following site structure on node.js with WebJob:
./server.js
./App_Data/jobs/continuous/myjob/run.cmd

While the project contains these two files, it is a WebJob-powered website, and you can use any deployment tool you prefer - ftp / WebDeploy / git / ...

Deployment Update


Constantly running WebJob ( continuous ) - after you deploy a new WebJob in place of the old one, the current running process will be interrupted and restarted with new binary files.
triggered - deployment update does not affect the currently running WebJob, but the next launch will happen with new files

Note: Before WebJob starts, its binary files are copied to a temporary directory, so you can always safely update the deployed WebJob without fear of file locking.

Caveat for Triggered WebJob


One problem that we encounter when deploying triggered WebJob in this way is that it actually turns out to be a WebJob that runs on demand, and you need to click the RUN ONCE button in the management portal to start it. There is currently no easy way to add a schedule for her.

A workaround could be to create an empty scheduled WebJob with the required name, and then the deployment will replace the files, but keep the current schedule.

Also popular now: