Doing unholy things in your Azure WebSites for background processing and batch jobs? I did, but have now been reformed. Feel like Worker Roles are a gigantic pain? You're not wrong. Enter Azure WebJobs. We will start with some boxes and lines explaining how WebJobs work, and where they fit in, and almost as importantly where they don't. Then we will go to some demos of how to write them, and the simple way of deploying. We will work with the different scheduling types : continuously running, triggered, and scheduled. Then we will talk about health and debugging, for each of these. Then we will work with how to get them to fit into your development workflow. I will even show you how to get your WebJobs to push updates through signalR. You will walk away with ways that WebJobs can help you be more productive and more decoupled in your code. Stop using hacks in websites to run batch jobs. Stop using Worker Roles to kill mosquitoes. Start using Azure WebJobs.
3. Who the #$@& is this guy??
WHO | What | When | Where | Why | How | OMG WHY?!
4. What is an
AzureWebJob?
Who| WHAT | When | Where | Why | How | OMG WHY?!
Location Name
Azure PaaS WebJob
Azure PaaS
(old)
Worker Role
Heroku Worker
App Harbor Worker Unithttps://flic.kr/p/5uJsLG
5. What is an
AzureWebJob?
Who| WHAT | When | Where | Why | How | OMG WHY?!
Options
Powershell
.BAT (Batch file)
Node.JS
Python
.exe
.NET Application
https://flic.kr/p/a2qceu
6. What is an
AzureWebJob?
Who| WHAT | When | Where | Why | How | OMG WHY?!
Can’t do
Run Servers
Invoke Server Applications
https://flic.kr/p/a2qceu
10. Where Does an Azure
WebJob Run?
Who| What | When | WHERE | Why | How | OMG WHY?!
1. With An AzureWebsite (W/AWS)
https://flic.kr/p/7fXoky
• Logically bound to a particular site
• Deployment options
• Separate Manual Deployment
• CLI
• Web Interface
• Continuous Deployment with site
• 1 …n
11. Where Does an Azure
WebJob Run?
2. With Only Other AzureWebJobs
https://flic.kr/p/ajkTkm
• Not Logically bound to a particular site
• Deployment options
• Separate Manual Deployment
• CLI
• Web Interface
• Independent git etc deployments.
• 1 …n
Who| What | When | WHERE | Why | How | OMG WHY?!
12. Who| What | When | Where | WHY | How | OMG WHY?!
Why Use AWebJob:
• Process Log Files
• Process Orders
• Migrate Deleted Items to Long term storage
• Compress Uploaded Images
• Add Watermarks to Images
• Run Nightly Tasks
• Import on premise data to azure
• Manage Videos for Smooth Streaming
• RSS Aggregation
• Migrating Log Files
• Long Running Tasks
• Complex Creation of User Records
• Interaction with slow 3rd party systems
• Convert JSON to XML
• Email users
• Decoupling
• Scalability
• OCR
• Billing
13. How to Manually UploadAWebJob :
1. Put files into a folder
2. Zip all the files in the folder
3. Go toWeb or CLI
Who| What | When | Where | Why | HOW | OMG WHY?!
14. How to “PiggyBack” Upload AWebJob :
1. Put files into a folder
2. Copy that folder to
App_Data/jobs/[continuous,triggered]/
3. Deploy As Usual
Who| What | When | Where | Why | HOW | OMG WHY?!
15. How to Continuously UploadAWebJob :
Who| What | When | Where | Why | HOW | OMG WHY?!
1. Create Project in Same Solution
2. Modify Build to copy that folder to
App_Data/jobs/[continuous,triggered]/
3. Deploy As Usual
16. How to Continuously UploadAWebJob :
1. Create Project in Same Solution
2. Modify Build to copy that folder to
App_Data/jobs/[continuous,triggered]/
3. Deploy As Usual
*Heavily Photoshopped for Clarity
Who| What | When | Where | Why | HOW | OMG WHY?!
17. How to create a .NETWebJob
Who| What | When | Where | Why | HOW | OMG WHY?!
1. File -> New -> Console Application
2. Add NuGet Packages for extra tooling
18. How to create a .NET WebJob
Who| What | When | Where | Why | HOW | OMG WHY?!
static void Main()
{
var host = new JobHost();
host.RunAndBlock();
}
public static void AzureQueue([QueueTrigger("myqueue")] string userJson) {}
public static void AzureQueueObject([QueueTrigger("myqueue")] Person person) {}
public static void SbQueue([ServiceBusTrigger("sbqueue")] string person) {}
public static void SbQueueObject([ServiceBusTrigger("sbobjectqueue")] Person person) {}
public static void Resize(
[BlobTrigger(@"images-input/{name}")] WebImage input,
[Blob(@"images-output/{name}")] out WebImage output) {}
19. How to TEST a .NETWebJob
Who| What | When | Where | Why | HOW | OMG WHY?!
//IN WEBJOB CLASS
public static Person LastPerson { get; set; }
public static void SbQueueObject([ServiceBusTrigger("sbobjectqueue")] Person person)
{
LastPerson = person;
Console.WriteLine("Service Bus Object Queue : {0}", person);
}
//INTEST CLASS
[Test]
public void PersonSetsLastPerson()
{
var dawn = PersonCreator.CreatePerson("Dawn");
ImageProcessing.SbQueueObject(dawn);
Assert.AreEqual(dawn,ImageProcessing.LastPerson);
}
20. How to Debug a .NET WebJob
Who| What | When | Where | Why | HOW | OMG WHY?!
https://cutyourhair.scm.azurewebsites.net/azurejobs/#/jobs
21. 1.Use A Backplane
2.Post Directly to the Backplane
How to Update SignalR from aWebJob
Who| What | When | Where | Why | How | OMG WHY?!
22. How to Update SignalR from aWebJob
Who| What | When | Where | Why | How | OMG WHY?!
23. How to Update SignalR from aWebJob
Who| What | When | Where | Why | How | OMG WHY?!
24. Who| What | When | Where | Why | How | OMG WHY?!
https://twitter.com/rustd
Pranav Rastogi
Program Manager, Azure WebJobs, ASP.NET
http://blog.amitapple.com/
Amit Apple
Senior Software Developer, Azure Web Sites
WhoTo Follow:
http://twitter.com/shanselman
Scott Hanselman
Microsoft
http://Friday.Azure.com
Learn More:
25. Who| What | When | Where | Why | How | OMG WHY?!
Mark Greenway
@MarkKGreenway