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 may want to deploy WebJob in other ways - ftp / git / WebDeploy. In this post, I will show how WebJob is stored in your Azure WebSites and how you can deploy a new WebJob.
Where are the WebJobs stored?
WebJobs are stored 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 the trigger (on demand or on schedule).
{job name} is the name of your WebJobs
')
Thus, a constantly working WebJob named myjob will be located in
site \ wwwroot \ App_Data \ jobs \ continuous \ myjob
What should be inside the webjob directory?
A directory with WebJob can contain from one to as many files as you need, but at least should contain a script that starts the WebJob process. Currently it can be:
- Command File (.exe / .cmd / .bat)
- Bash (.sh)
- Javascript (.js for node.js)
- PHP (.php)
- Python (.py)
The scripts run automatically according to the following logic:
- First, a file with the name run is searched. {Supported extension} (the first found wins)
- If it is not found, any file with a supported extension is searched.
- If not found, it is not a WebJob
Note: if you have any other script execution engine that you want to use
and which is not currently supported, you can always create a file run.cmd 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 place 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 the binary files (containing at least one supported script file) there. Then the WebJob will be determined automatically and will start immediately.
Deploying WebSite + WebJobs
To deploy a WebJobs site, all you have to do is make sure that you deploy your WebJob to the right place. For an example, take a look at the following site structure on node.js with a WebJob:
./server.js
./App_Data/jobs/continuous/myjob/run.cmd
As long as the project contains these two files - this is a website with a constantly running WebJob, 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, the current running process will be interrupted and restarted with new binary files.
triggered - the update update does not affect the currently running WebJob, but the next launch will happen with new files
Note: Before a WebJob is launched, its binary files are copied to a temporary directory, so you can always safely update a deployed WebJob without fear of locking files.Caution on Triggered WebJob
One problem we face when deploying a triggered WebJob in this way is that, in fact, it turns out WebJob, which is launched on demand, and you need to click the RUN ONCE button in the management portal to start it. At the moment there is no easy way to add a schedule for it.
A workaround would be to create an empty scheduled WebJob with the required name and then the deployment will replace the files, but keep the current schedule.