Partager via


Azure Web Apps (Web Sites) and WebJobs using the Azure Preview Portal

In todays blog, you will be learn now to use the Azure Preview Portal to create a simple and to upload a webjob to the web app (web site). The webjob will of the powershell type and is fully functional, I didn’t add the code since it is only three lines that you can cut and paste if you want to. If you don’t have access to Azure right now, I added enough screens that you could simulate the workflow if you are studying for the 70-532 exam. The screens shown are the latest Azure preview portal screens as of 5/22/2015.

This is part 1 of a series of an TBD number of blogs.  Where TBD stands for “To Be Determined” but likely around 8 blog entries.

Sources:

MVA:

· A Lap Around Azure Websites

Articles:

· Run Background tasks with WebJobs

 

                                                        Next Blog

 

Problem statement

You work for a company that needs to upload images to a web site, they don’t have much money and hope to test out the value of the idea using the basic MSDN account, which gives you $200 or $150 for your MSDN Subscription. The owner of the company just got divorced and bought a new car, so money is tight, but the owner has promised that if this takes off you will get 25% of all net profits (if you don’t know what net profits mean, seriously look it up, sounds better than it is). The owner is also leaving on a long vacation with new paramour, so if you get this going quickly you might be able to goof off on some other things you want to work on. Since you will getting part of the NET profits, not GROSS profits you must design your system efficiently, but it must scale appropriately, be secure and not reveal any trade secrets.

 

What you need to do

You will need to:

· Create a Web App (Web Site)

· Process the images

· Run a copyright analysis against the pictures

· Make sure you that in the future you can upload and use a similar process against text based items

· Store up to 500 gigabytes of images

· Track the images using an existing SQL database

· Use OAuth for identity services

Creating the Web App (Web Site):

If this is your first time in Azure, or if you don’t have access to Azure, I have shown a step by step process for creating a WebJobs in the next section. It is a pretty long process so keep scrolling, feel free to print out etc., the images following the explanation and code for this section, but are not in line with the section, it is under the “What are we doing here”.

Process you might use

1. Using Azure, sign in, this will work with the Dreamspark Azure, Free Azure, MSDN Azure and Organizational Azure.

2. Using the “Azure Preview Portal”, in contrast to the Azure Portal, I think the Azure Preview Portal is easier to use, but is an acquired taste like a 4 shot espresso. (Which is shown in the image step by step process in the next section.) If you are used to using the Azure Portal then you are likely not reading this.

3. Use the +New block in the upper right corner to generate a “Free” hosting site, because you are only testing this idea, don’t pick standard or others.

a. Note: The Standard and Premium versions double their ram size for each increase in number, sort of. S1 is 1.76 gigs, S2 is 3.5 gigs.

b. I am not sure how this maps to a tablet computer ram, but it isn’t the same relationship.

4. Follow the step-by-step to generate the web job

5. Now create a simple powershell commend that can be invoked from a command line and name it ListProcessesPS.cmd, just like in the referenced blog, Nick’s blog:

a.PowerShell -Command "& {Get-Process}"

b. If you don’t copy and paste the line, make sure to add the double quotes, also don’t add exe to the powershell.

6. You should see the following output when you click on the scm or kudu webpage get your magnifying glass out, the box is added by author:clip_image002

7. You will see this in the SCM or Kudu webpage that looks like this:

clip_image003

8. Now you will need to make something more useful, so combine a powershell script (.exe) with the command line file (.cmd), so you would create a command file that runs a separate powershell script.

a. Process:

· Write a simple command file that will run a powershell executable, to get the running processes:

· PowerShell -Command "& {Get-Process}"

· Suggested name for the file: GetProcess.ps1

· Modify your command file (cmd) that includes a way to get around the digital signature requirement (will show how to use a digital signature later):

· PowerShell -ExecutionPolicy RemoteSigned -File Get-Processes.ps1

· Suggested name of the file: ListProcessPS.cmd

· Zip up both of the files

· Suggested name of the file: ListRunningProcesses.zip

· Upload your zip file (see the step-by-step)

b. You should see the following on the scm or kudu Web App (Web Site) if you download the data:

[05/22/2015 20:55:34 > d4cd0e: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob

[05/22/2015 20:55:34 > d4cd0e: SYS INFO] Status changed to Starting

[05/22/2015 20:55:34 > d4cd0e: SYS INFO] Run script 'ListProcesses.cmd' with script host - 'WindowsScriptHost'

[05/22/2015 20:55:34 > d4cd0e: SYS INFO] Status changed to Running

[05/22/2015 20:55:34 > d4cd0e: INFO]

[05/22/2015 20:55:34 > d4cd0e: INFO] D:\local\Temp\jobs\continuous\wwee\yigtziwo.140>powershell -ExecutionPolicy RemoteSigned -File GetProcesses.ps1

[05/22/2015 20:55:37 > d4cd0e: INFO]

[05/22/2015 20:55:37 > d4cd0e: INFO] Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName

[05/22/2015 20:55:37 > d4cd0e: INFO] ------- ------ ----- ----- ----- ------ -- -----------

[05/22/2015 20:55:37 > d4cd0e: INFO] 50 8 3576 5084 32 0.05 11444 cmd

[05/22/2015 20:55:37 > d4cd0e: INFO] 240 25 39964 39840 201 0.95 27300 powershell

[05/22/2015 20:55:37 > d4cd0e: INFO] 244 21 39628 39468 192 1.08 27372 powershell

[05/22/2015 20:55:37 > d4cd0e: INFO] 1288 109 139472 156692 745 133.02 25268 w3wp

[05/22/2015 20:55:37 > d4cd0e: INFO]

[05/22/2015 20:55:37 > d4cd0e: INFO]

[05/22/2015 20:55:37 > d4cd0e: SYS INFO] Status changed to Success

[05/22/2015 20:55:37 > d4cd0e: SYS INFO] Process went down, waiting for 60 seconds

[05/22/2015 20:55:37 > d4cd0e: SYS INFO] Status changed to PendingRestart

[05/22/2015 20:56:38 > d4cd0e: SYS INFO] Run script 'ListProcesses.cmd' with script host - 'WindowsScriptHost'

[05/22/2015 20:56:38 > d4cd0e: SYS INFO] Status changed to Running

[05/22/2015 20:56:38 > d4cd0e: INFO]

[05/22/2015 20:56:38 > d4cd0e: INFO] D:\local\Temp\jobs\continuous\wwee\yigtziwo.140>powershell -ExecutionPolicy RemoteSigned -File GetProcesses.ps1

[05/22/2015 20:56:41 > d4cd0e: INFO]

[05/22/2015 20:56:41 > d4cd0e: INFO] Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName

[05/22/2015 20:56:41 > d4cd0e: INFO] ------- ------ ----- ----- ----- ------ -- -----------

[05/22/2015 20:56:41 > d4cd0e: INFO] 50 8 3580 5092 32 0.03 20400 cmd

[05/22/2015 20:56:41 > d4cd0e: INFO] 244 21 39748 39528 192 1.17 24544 powershell

[05/22/2015 20:56:41 > d4cd0e: INFO] 240 25 40504 39904 201 0.94 27056 powershell

[05/22/2015 20:56:41 > d4cd0e: INFO] 1304 111 139336 156644 744 133.16 25268 w3wp

[05/22/2015 20:56:41 > d4cd0e: INFO]

[05/22/2015 20:56:41 > d4cd0e: INFO]

[05/22/2015 20:56:41 > d4cd0e: SYS INFO] Status changed to Success

[05/22/2015 20:56:41 > d4cd0e: SYS INFO] Process went down, waiting for 60 seconds

[05/22/2015 20:56:41 > d4cd0e: SYS INFO] Status changed to PendingRestart

What just happened?

We have created a webjob that was zipped up and then installed into the Web App (Web Site) which was run continuously. By using Powershell, this is an efficient process using the tools you are familiar with.

Scroll down to see the step by step process using the Azure Preview Portal, which has variations from the Azure Portal, mainly the Azure Preview Portal allows you to upload most executables, the Azure Portal only allows the zip files.

 

 

Step by Step

Open your Azure account and click on New

clip_image005

Now select

Web + Mobile

clip_image007

Select

Web App

 

clip_image009

When you select the Pricing Tier you will be presented with some expensive offers.

Don’t pick these if you are just getting started.

 

By the way the prices are quite good for what you get.

 

Instead, in the upper right hand corner click on

View All

 

 

clip_image011

Scroll down till you see the Free Box, 1 GB of storage, not bad right?

 

clip_image013

Now you can create a resource group. This allows you to group your website with other Azure products so that you can change the plans all in one place. Very handy.

 

Or you could use resource groups your team puts together.

clip_image014

Now select your Location. Pick a geographical site closest to you. Why? Geo location is important, some facilities have products that others don’t. Also there is the Speed of Light considerations, it does take time for signals to travel, not much, but it is a consideration.

 

Also, you may have legal reasons that require the data be hosted in specific locations.

 

Finally click the create button in the lower left hand part of the “blade”.

 

This will take a few minutes to generate.

clip_image015

Now switch back to the Settings Blade, click the WebJobs line.

clip_image017

Click on the WebJobs and yes the words Web and Jobs are stuck together with the capital.

Annoying? Perhaps.

 

Then click the “+Add” link

clip_image019

Create your WebJob powershell,

Make sure you have the Azure SDK downloaded and on your machine. You don’t use it for this example, but get it downloaded!

 

This is the Powershell ISE

I like it better than the powershell command shell

clip_image021

Now I have uploaded the incorrect file, on purpose. It’s not a mistake if I call it!

 

We will run the WebJob Continously, which is not a good idea since if you are paying for things it will run up costs. So be thoughtful.

 

If you prefer the Azure Portal then you will have to zip up the file you are uploading.

 

This is the Azure Preview Portal

clip_image022

Add and make the changes to the files so that you can use the cmd file to run another powershell file. This is important for long term design

Now you will need to click on the parallel logging website, which in our case has the form shown to the right. In tiny print.

 

As you can tell the URL has information about your webjob.

 

scm=

site control manager

 

https://freeloader.scm.azurewebsites.net/azurejobs/#/jobs/continuous/wwee

clip_image024

 

If all goes well you will see the table of information shown in the text explanation

 

Conclusion for this section

We have created a Web App (Web Site) and a Web Job that uses two scripts, one a command file that launches when the webjob runs and then runs another powershell file. The webjob runs continuously, which really means that is runs then stops and then one minute later it runs again.

Webjobs can run once, continuously and on a schedule. To be efficient you will need to determine the bet execution plan. Webjobs can be deployed continuously or by using Visual Studio, which will be discussed in a later section.

Other excellent resources for your consideration:

MVA:

A Lap Around Azure Websites

Articles:

Run Background tasks with WebJobs