cut your hair and get an azure webjob

25
CUT YOUR HAIR AND GET AN AZURE WEBJOB! Mark Greenway @MarkKGreenway Who | What | When | Where | Why | How | OMG WHY?!

Upload: mark-greenway

Post on 11-Nov-2014

113 views

Category:

Technology


3 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Cut your hair and get an azure webjob

CUT YOUR HAIR AND GET AN AZURE WEBJOB!

Mark Greenway@MarkKGreenway

Who | What | When | Where | Why | How | OMG WHY?!

Page 2: Cut your hair and get an azure webjob

THANKS SPONSORS!

Who | What | When | Where | Why | How | OMG WHY?!

Page 3: Cut your hair and get an azure webjob

Who the #$@& is this guy??

Him

WHO | What | When | Where | Why | How | OMG WHY?!

Page 4: Cut your hair and get an azure webjob

What is an Azure WebJob?

Who| WHAT | When | Where | Why | How | OMG WHY?!

Location NameAzure PaaS WebJobAzure PaaS

(old)Worker Role

Heroku WorkerApp Harbor Worker Unithttps://flic.kr/p/5uJsLG

Page 5: Cut your hair and get an azure webjob

What is an Azure WebJob?

Who| WHAT | When | Where | Why | How | OMG WHY?!

Options

Powershell

.BAT (Batch file)

Node.JS

Python

.exe

.NET Applicationhttps://flic.kr/p/a2qceu

Page 6: Cut your hair and get an azure webjob

What is an Azure WebJob?

Who| WHAT | When | Where | Why | How | OMG WHY?!

Can’t do

Run Servers

Invoke Server Applications

https://flic.kr/p/a2qceu

Page 7: Cut your hair and get an azure webjob

When Does an Azure WebJob Run?

Who| What | WHEN | Where | Why | How | OMG WHY?!

1. Triggered

2. Continuous

© 2013 Tim Buss

Page 8: Cut your hair and get an azure webjob

When Does an Azure WebJob Run?

Who| What | WHEN | Where | Why | How | OMG WHY?!

1. Triggered

© 2013 Tim Buss

• Scheduled• Manual

Page 9: Cut your hair and get an azure webjob

When Does an Azure WebJob Run?

Who| What | WHEN | Where | Why | How | OMG WHY?!

2. Continuous

© 2013 Tim Buss

• Runs All The Time (with Always On)• .NET Triggers Run (with SDK)

Page 10: Cut your hair and get an azure webjob

Where Does an Azure WebJob Run?

Who| What | When | WHERE | Why | How | OMG WHY?!

1. With An Azure Website (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

Page 11: Cut your hair and get an azure webjob

Where Does an Azure WebJob Run?

2. With Only Other Azure WebJobs

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?!

Page 12: Cut your hair and get an azure webjob

Who| What | When | Where | WHY | How | OMG WHY?!

Why Use A WebJob:

• 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

Page 13: Cut your hair and get an azure webjob

How to Manually Upload A WebJob :

1. Put files into a folder 2. Zip all the files in the folder 3. Go to Web or CLI

Who| What | When | Where | Why | HOW | OMG WHY?!

Page 14: Cut your hair and get an azure webjob

How to “PiggyBack” Upload A WebJob :

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?!

Page 15: Cut your hair and get an azure webjob

How to Continuously Upload A WebJob :

Who| What | When | Where | Why | HOW | OMG WHY?!

1. Create Project in Same Solution2. Modify Build to copy that folder to

App_Data/jobs/[continuous,triggered]/3. Deploy As Usual

Page 16: Cut your hair and get an azure webjob

How to Continuously Upload A WebJob :

1. Create Project in Same Solution2. 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?!

Page 17: Cut your hair and get an azure webjob

How to create a .NET WebJob

Who| What | When | Where | Why | HOW | OMG WHY?!

1. File -> New -> Console Application 2. Add NuGet Packages for extra tooling

Page 18: Cut your hair and get an azure webjob

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) {}

Page 19: Cut your hair and get an azure webjob

How to TEST a .NET WebJob

Who| What | When | Where | Why | HOW | OMG WHY?!

//IN WEBJOB CLASSpublic static Person LastPerson { get; set; }public static void SbQueueObject([ServiceBusTrigger("sbobjectqueue")] Person person){ LastPerson = person; Console.WriteLine("Service Bus Object Queue : {0}", person);}

//IN TEST CLASS[Test]public void PersonSetsLastPerson(){ var dawn = PersonCreator.CreatePerson("Dawn"); ImageProcessing.SbQueueObject(dawn); Assert.AreEqual(dawn,ImageProcessing.LastPerson);}

Page 20: Cut your hair and get an azure webjob

How to Debug a .NET WebJob

Who| What | When | Where | Why | HOW | OMG WHY?!

https://cutyourhair.scm.azurewebsites.net/azurejobs/#/jobs

Page 21: Cut your hair and get an azure webjob

1.Use A Backplane2.Post Directly to the Backplane

How to Update SignalR from a WebJob

Who| What | When | Where | Why | How | OMG WHY?!

Page 22: Cut your hair and get an azure webjob

How to Update SignalR from a WebJob

Who| What | When | Where | Why | How | OMG WHY?!

Page 23: Cut your hair and get an azure webjob

How to Update SignalR from a WebJob

Who| What | When | Where | Why | How | OMG WHY?!

Page 24: Cut your hair and get an azure webjob

Who| What | When | Where | Why | How | OMG WHY?!

https://twitter.com/rustdPranav RastogiProgram Manager, Azure WebJobs, ASP.NET

http://blog.amitapple.com/Amit AppleSenior Software Developer, Azure Web Sites

Who To Follow:

http://twitter.com/shanselmanScott HanselmanMicrosoft

http://Friday.Azure.com

Learn More:

Page 25: Cut your hair and get an azure webjob

Who| What | When | Where | Why | How | OMG WHY?!

Mark Greenway@MarkKGreenway