다음을 통해 공유


Azure Webjobs - The Quick Guide

Azure Websites enables you to run programs or scripts in your website in three ways: on demand, continuously, or on a schedule. There is no additional cost to use Microsoft Azure WebJobs. You can use webjobs along with Azure websites or Azure Mobile Services.

There are different types of running mode webjobs provides -: Triggered and Continuous

1: Triggered Jobs

Triggered tasks are initiated by user or by helper services like Azure Scheduler; it happens over a schedule, or when some event happens. It's secured over http s and its protected by deployment credentials. And the instance used for webjobs is determined by load balancer, its configurable too.

2: Continuous Jobs

Continuous jobs are always on type job, which runs on a loop. The background service monitors running state and invokes if needed for jobs. This type of jobs runs in all available instances and if needed can be configured to a singleton.

One should be a bit cautious while using webjobs, as its using the same instance of websites, so sometimes it may cause performance issues. In such cases, you can use scheduler to trigger some external services like HD inside or whatever your choice.

Creating a simple webjob

1: Make a simple service, normally an executable file, like console application, anything that runs on a website scenario like js, batch files etc. The service is actually an entry point, so you can use any executables, batch files or powershell. Checkout MSDN for full list of supportable file for webjobs. And regarding the executable program, you don't need to import any webjobs specific name space in your application.

2: Build the program, zip the executable file. One important thing to remember at this stage is that, your executable file should be in the root of zipped folder; ie it should not be inside another folder inside zip file. Along with executable files, you can include .pdb files, if you like to debug your service.

3:Go to azure portal, your website dashboard , webjobs tab.

4: Click add webjobs, upload your zipped folder. Select the run mode(on demand for now). Save

That's all you have successfully created a webjob. Here you uploaded the zip file for the job. Please note that zip is one of the transport mechanism to deploy webjobs. You can also leverage other mechanisms like GIT or webdeploy, depends on your decision.

You can run the webjobs on demand or scheduled. In this article, we created an on demand webjob, you can also try to create scheduled webjobs, the run mode should be the one you need to make change.

Once you run the webjob, you can click on the logs to see the status of your webjobs. A download link will be provided by Azure, which helps you to view the output of the service.

That's all about the basics of webjobs. You can use webjobs for lightweight processing in your websites and mobile services. Webjobs are also scalable, you can take advantage of it when you scale your websites. Webjobs uses the your websites resource and instance, so try to tweak the service, so that it executes faster. For complex, long running procesess, you can take advantage of an external service and trigger that or make use of Azure Queues to enable offline(asynchronous processing)

All the best, Have a Nice Day