DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Using Azure WebJobs to Automate Stuff

Using Azure WebJobs to Automate Stuff

Azure WebJobs, a piece of Azure App Service, allows you to run scheduled scripts. See how you can use it to scheduled and automate basic tasks.

Simon Foster user avatar by
Simon Foster
·
Jul. 05, 17 · Tutorial
Like (1)
Save
Tweet
Share
4.20K Views

Join the DZone community and get the full member experience.

Join For Free

I keep hearing about Azure WebJobs but I have never used them. Time to change this.

WebJobs are a feature of Azure App Service that can run a script at a specific time. In my case, I would like to hit a specific URL of my website at the same time every day.

WebJobsTo the right, you can see an example of the WebJobs form on the Azure portal that you need to fill in.

You need to supply a name for your WebJob.

You need to upload the script that will run. In my case, I used a PowerShell script. My script basically just loads the URL specified.

$progressPreference = "silentlyContinue";
$result = Invoke-WebRequest -Uri ("https://www.google.com") -Method Get -UseBasicParsing;


"Type", in the above image, refers to whether your job to be triggered or to run continuously. I want it to be triggered.

The Triggers field refers to whether you want it to be scheduled or manual, something that you can run on an ad hoc basis. I, of course, want it scheduled.

If you are familiar with Linux CRON, then the next box will make sense to you. For everyone else, I will try and make sense of it. The box consists of six numbers that can either have a value or a *. The numbers correspond to the following: {second} {minute} {hour} {day} {month} {day of the week}.

An hourly job would be expressed as 0 0 * * * * — every day of the week, every month, every day, every hour, and only when the minute and second equals zero. For more help with this, check out the MSDN docs about it. I want to use 0 30 21 * * * to run daily at 9:30 P.M.

That’s it! Everything is set up, and now it's time to wait and see if it works.

Oh No!

It failed to run at the specified time.

The reason for this is that the scheduler requires the Always On feature to be turned on, which is not available in the free App Service. Before you reach for your wallets, I found a solution in this blog post that allows them to run on the free tier.

The thinking behind this solution is that you need to keep the website alive throughout the day, so Tom has created a script that does this. His script can be found on his blog or on his GitHub page.

Set this script up to run every 5 minutes (0 */5 * * * *) like the example above.

The next thing you need to do is create a custom connection string in the application Settings blade called SecretThing. Tom’s script references this to access the website and keep it alive. The password you need to put in SecretThing can be found in you publish profile (downloaded from the Overview blade in the Azure portal). For more details and a better explanation, check out Tom’s blog.

One last thing to mention about WebJobs is that you can see details about when they have run at https://[YourWebAppName].scm.azurewebsites.net/azurejobs/#/jobs. This can be a great place to help debug your scripts.

azure

Published at DZone with permission of Simon Foster, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Gentle Introduction to Kubernetes
  • Use AWS Controllers for Kubernetes To Deploy a Serverless Data Processing Solution With SQS, Lambda, and DynamoDB
  • What Are the Benefits of Java Module With Example
  • A Beginner's Guide to Infrastructure as Code

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: